Got react project and get list of needed inputs from BE. Creating validating Schema object need to use or not fields depending on condition exist this field in object from BE or not. Got this solution but don't know is it ok?
const validationSchema = yup.object().shape({ ...('phone' in fieldsList) && {'phone': yup.string().required('required')}, ...('password' in fieldsList) && {'password': yup.string().required('required')}, ...('email' in fieldsList) && {'email': yup.string().required('required')}, ...('name' in fieldsList) && {'name': yup.string().required('required')},});
1.4m articles
1.4m replys
5 comments
57.0k users