Jared Palmer is the creator and maintainer of Formik, the premiere forms solution for React applications. Formik makes forms in React easy by managing your form's state and providing validation on all of your fields. Under the hood, Formik is using React Hooks, and today we are going to make our own mini Formik with them!
useReducer
is the hook to use for any complex state management. useReducer
follows the redux principle of returning a modified copy of the state. Writing a custom hook with useReducer
lets you decouple your handlers and state from the component into a testable function.
The useEffect
hook isn't the same as the componentDid...
lifecycle hooks. It runs on each render, and you can pass an array that tells it to not run if the value hasn't changed from the previous render.
onBlur
should be used over onMouseDown
so that errors aren't shown before the user types
in https://jaredpalmer.com/formik/docs/overview if you can give the codesanbox or codepen link it will help a lot
nice work