useFormikContext() - rkaku/formik-material-ui GitHub Wiki
useFormikContext(): FormikProps
importReactfrom'react';import{useFormikContext,Formik,Form,Field}from'formik';constAutoSubmitToken=()=>{// Grab values and submitForm from contextconst{ values, submitForm }=useFormikContext();React.useEffect(()=>{// Submit the form imperatively as an effect as soon as form values.token are 6 digits longif(values.token.length===6){submitForm();}},[values,submitForm]);returnnull;};constTwoFactorVerificationForm=()=>(<div><h1>2-step Verification</h1><p>Please enter the 6 digit code sent to your device</p><FormikinitialValues={{token: ''}}validate={values=>{consterrors={};if(values.token.length<5){errors.token='Invalid code. Too short.'}returnerrors}}onSubmit={(values,actions)=>{setTimeout(()=>{alert(JSON.stringify(values,null,2));actions.setSubmitting(false);},1000);}}><Form><Fieldname="token"type="tel"/><AutoSubmitToken/></Form></Formik></div>);