I'm following this example for dependent fields https://formik.org/docs/examples/dependent-fields
At this point
const {
values: { taxRefundAmount },
setFieldValue,
} = useFormikContext()
I want to destructure values based on a certain condition like this for example
const {
values: { props.name === 'taxRefundVATAmount' ? taxRefundAmount : taxChargeAmount },
setFieldValue,
} = useFormikContext()
Of course, this throws an error. Is this even possible?
You could do something like this, get the bits you need and do it the simple way without the spread operator:
const formikContext = useFormikContext();
const setFieldValue = formikContext.setFieldValue ;
const values = props.name === 'taxRefundVATAmount'
? formikContext.values.taxRefundAmount
: formikContext.values.taxChargeAmount;