Skip to content

Instantly share code, notes, and snippets.

@danielkcz
Last active December 27, 2019 09:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielkcz/1bf4c8453989ca988e73c49816773a8e to your computer and use it in GitHub Desktop.
Save danielkcz/1bf4c8453989ca988e73c49816773a8e to your computer and use it in GitHub Desktop.
Formik with MobX #2
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);
}
}), []
);
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