Skip to content

Instantly share code, notes, and snippets.

View alexander-elgin's full-sized avatar

Alexander Elgin alexander-elgin

View GitHub Profile
@alexander-elgin
alexander-elgin / formik-mobx.js
Created December 20, 2019 11:44 — forked from danielkcz/formik-mobx.js
Formik with MobX
function useFormik(props) {
// useState to keep the same observable around without recreating it on each render
const [formik] = React.useState(() =>
mobx.observable({
values: props.initialValues || {},
touched: {}
})
)
// just mutate state, this function itself can be considered an action+reducer