Open johnrom opened 3 years ago
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 60 days
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 60 days
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 60 days
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 60 days
🔌 Formik Plugins
I've identified several use cases across Formik issues for adding a plugin system to Formik. The functionality of a plugin would be:
useFormik
It would allow us to use composition to expand Formik's functionality without adding responsibilities to the core library.
Example Uses
Strongly-typed Status. Currently, Formik Status is kind of a one-off weird thing that doesn't have anything to do with Formik's Core functionality but we provide to users for convenience, as a shortcut to creating their own separate Context. This could probably be done with a plugin with stronger types without adding a Type parameter to the root
Formik
component oruseFormik
hook. For backwards compatibility this plugin would be used by the "default initializer" with a type ofany
.Remove Yup. I've never in my life used Yup but all my projects using Formik have it installed! heh! Yup is great, but it's not suitable to everyone's needs. It should live in a Plugin. For backwards compatibility this plugin would be used by the "default initializer".
Undo/redo. One could create a plugin that records reducer history and allows replayability.
Event Listeners. Some devs would like to listen to events like "onFormChange", etc. A plugin could enable that functionality by generating side effects from dispatches.
formik-native
. Currently Formik's non-RN core functionality actually tests for React Native's presence in certain cases (specificallygetValueFromEvent
in v3), but this could be done via a Plugin instead.Disabling entire form
Managing disabled inputs
The Proposed API
I propose we create Formik initializers using
createFormik
which we then pass touseFormik
orFormik
to add extra functionality to the reducer. It would be something like: