pass useCallback function to Formik innerRef? #3271
-
I'm wondering if anyone has experience passing a callback from Currently, I have the following, and it works for triggering Formik submission from outside the const MyModal = () => {
const [isSavingDisabled, setSavingDisabled] = useState( false )
const formikRef = useRef()
const doSave = () => {
if ( formikRef.current ) {
formikRef.current.handleSubmit()
}
}
return (
<Modal>
<ModalHeader>My Modal Header</ModalHeader>
<ModalBody>
<Formik innerRef={formikRef} {...formikProps}>
{ /* Form body */ }
</Formik>
</ModalBody>
<ModalFooter>
<Button disabled={isSavingDisabled} onClick={doSave}>
Save
</Button>
</ModalFooter>
</Modal>
)
} I need to: 1) preserve a reference to I've seen that |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
It turns out that using the |
Beta Was this translation helpful? Give feedback.
It turns out that using the
useFormik
hook with theFormikProvider
context provider as described here (#2746) does exactly what I'm looking for. I spent hours searching for a solution and some documentation of this "pattern" of Formik usage would have been incredibly helpful.