-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[v2] Hooks #1063
[v2] Hooks #1063
Conversation
Why the rename of |
I don't have the time to make this into a formal PR right now but maybe it'll provide a little inspiration. It's a proof-of-concept of Formik working with hooks. Because of the imperative API exposed by formik, the key I found is to mostly use refs internally rather than state, otherwise the values will get stale, e.g. if you set a field and call submitForm in the same event handler. It's just a first pass, so I'm sure there's plenty of room for improvement, but it seems to work alright: https://gist.github.com/tgriesser/fdd08da075fec80328792319606c76e5 |
I (think) I'm almost done with useFormik. I made one perf improvement which I think we should push down to v1: avoid toggling isValidating if field-level validation is synchronous. |
@tgriesser hrm. that's definitely a footgun with calling submit form in the same handler. i wonder if there is a way to avoid that aside from ref + force update. refs won't show up in dev tools for example. |
Pretty close here. There is definitely some quirks without the state updater callback |
How can I extend it with warnings? |
If we decide to allow a |
Any way to progress this ticket? :) |
Will |
@MatyCZ Is it really that hard to at least read the previous comment? 🙄 😆 |
Maybe remove the |
Any progress with the docs? |
I am working on docs this week |
I realize the docs aren't ready but does there happen to be a hooks code example sitting around somewhere? 😀 |
@jaredpalmer thanks! A video will be also appreciate it 👍 |
A demo, until we see something from @jaredpalmer
|
AFAIK the |
And formik handles the
|
Then how to validation rules, initial values? |
Ah ok, now I know the difference between I‘m not sure if the former is meant for public use, but I think it can be used like this:
https://github.com/jaredpalmer/formik/blob/master/src/Formik.tsx#L125 I think you need the provider though when you use Formik‘s |
https://github.com/Availity/availity-react/tree/master/packages/form Our whole reactstrap form, selects, and datepickers are built using formik v2. Probably a good production example of this. Sorry if this is frowned upon to do this until a stable release 😏 |
@GoPro16 checked your code but don't see references to |
We use the useField hook and the useFormikContext hook the most. We don't ever use https://availity.github.io/availity-react/form/components/form/ |
@jaredpalmer release the feature to next version? |
As [this comment](jaredpalmer/formik#1063 (comment)) said, the `enableReinitialize` feature of `useFormik` hook, is missing in `v2.0.1-alpha.0`, this PR might resolve this problem.
As [this comment](jaredpalmer/formik#1063 (comment)) said, the `enableReinitialize` feature of `useFormik` hook, is missing in `v2.0.1-alpha.0`, this PR might resolve this problem.
As [this comment](jaredpalmer/formik#1063 (comment)) said, the `enableReinitialize` feature of `useFormik` hook, is missing in `v2.0.1-alpha.0`, this PR might resolve this problem.
As [this comment](jaredpalmer/formik#1063 (comment)) said, the `enableReinitialize` feature of `useFormik` hook, is missing in `v2.0.1-alpha.0`, this PR might resolve this problem.
Improvements
<Field as>
prop (Create <Field as> and deprecate <Field component> and <Field render> #1406)meta
prop to<Field children>
(Create <Field as> and deprecate <Field component> and <Field render> #1406)useFormik
from<Formik>
onReset
andhandleReset
testssetSubmitting(false)
needed)useField
's second element is field metadata (Add meta prop to Field, FastField #343)initialErrors
,initialTouched
,initialStatus
(Add initialXXXX and fix isValid #1410)isValid
(Add initialXXXX and fix isValid #1410)<Field >
's useshandleBlur('path')
andhandleChange('path')
override(executeBlur should not inspect
event
ifpath
is set #1113)Breaking Changes
FormikActions
have been renamed toFormikHelpers
console.error
in its warnings, but ratherconsole.warn
Deprecations
These are just warnings for now.
<Field render>
(Create <Field as> and deprecate <Field component> and <Field render> #1406)<Field component>
(Create <Field as> and deprecate <Field component> and <Field render> #1406)isInitialValid
and fixisValid
(Add initialXXXX and fix isValid #1410)Documentation
useField
<FieldGroup>
"<FormikConsumer>
useFormikContext
useFormik
Feel free to start making PR's to this branch. This is going to take a minute to figure out as there are a LOT of new paradigms.
#1046 #1005