I'm trying to use the ref in Formik to let useEffect listen for changes in form field values. But when I run:
const formikRef = useRef(); // this gets passed to Formik's ref prop on component render
React.useEffect(() => {
// do something
}, [formikRef.current.state.values.MyFormFieldName]);
It fails with this error: Cannot read property 'state' of undefined
I'm on Formik v1.3 and I can't directly access the Field component since I'm using a custom wrapper component (as part of an internal UI library) and it doesn't expose all the Field props.
EDIT:
I can do formikRef.current?.state.values.MyFormFieldName but that still doesn't cause useEffect to fire when MyFormFieldName changes.