Last active
December 27, 2019 09:11
-
-
Save danielkcz/1bf4c8453989ca988e73c49816773a8e to your computer and use it in GitHub Desktop.
Formik with MobX #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
React.useEffect(() => | |
mobx.autorun(() => { | |
if (props.validate) { | |
// MobX will see use of formik.values and rerun this function whenever it is mutated | |
formik.errors = props.validate(formik.values); | |
} | |
}), [] | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
React.useEffect( | |
() => { | |
if (props.validate) { | |
const errors = props.validate(state.values); | |
dispatch({ type: 'SET_ERRORS', payload: errors }); | |
} | |
}, | |
[state.values] | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment