I have initialValues in Formik but I want to assign values in accordance with another field.
I have this code:
const initialValues: MyValues = {
fieldType: fieldType.FIELDA,
fieldInformation: '',
fieldB: '',
dateRange: {
from: lastWeek,
to: today,
},
};
I want something like:
const initialValues: MyValues = {
fieldType: fieldType.FIELDA,
fieldInformation: '',
fieldB: fieldType === fieldType.FieldA ? 'all' : '',
dateRange: {
from: lastWeek,
to: today,
},
};
So fieldB depends on the value of fieldType. How can I achieve that? The problem is that fieldType is a radioButton and I want to initialize with ” if fieldType.FIELDB is chosen.