Minor Changes
-
Add
FieldHelpers
object to the array returned byuseField
: #2124. This
exposes three helper functions to allow you to imperatively change the
field in question:setValue(value: any)
setTouched(value: boolean)
setError(value: string)
Before
const MyInput = (props) => { const formik = useFormikContext() const [field, meta] = useField(props) const handleThing = () => { formik.setFieldValue(props.name, 'boop') } // ... }
After
const MyInput = (props) => { const [field, meta, helpers] = useField(props) const handleThing = () => { helpers.setValue('boop') } // ... }
Credits
Huge thanks to @drivasperez for helping!