-
-
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
useFieldArray in 2.0 #1476
Comments
BTW, it would be convenient to be able to use a non-context-based way to retrieve the arrayHelper const form = useFormik()
form.getArrayHelper("friends"); As with |
Agree. Good idea |
Maybe: const formikbag = useFormik()
formikbag.getFieldArrayHelper("friends"); |
Didn't see this issue get tagged with |
V2 user here--would love to see |
would love to see this too |
In the meantime, creating a custom hook really boosted performance compared to FieldArray for me (using immutability-helper and it's still a wip, but at least it's a start):
|
This is a great concept, did it ever get completed? I'd love to use this in my project. Thanks! |
Not sure if you're asking me (or maybe Jared for an official one?), but in case anyone wants it, my custom hook: https://gist.github.com/joshsalverda/d808d92f46a7085be062b2cbde978ae6 Sorry in advance if you're not already using immutability-helper... I think it's 1-1 with what formik provides. Can likely be improved, but it seems to be working fine for my use cases and all my tests pass so I'm happy 😄Not too worried since once this is officially implemented I'll end up deleting it anyways. Had to use a ref to store an extra array since field.value didn't seem to update fast enough in things like loops where you might be pushing a lot of values in. Not sure if there's a better way to handle that 🤷♂ |
Any updates on that? |
Just a note for anyone using my custom hook above: I discovered a pretty nasty bug that you may run into. If your array never changes then it's all good, but if it does change then you will run into it. Has to do with the ref I'm using, if field.value changes outside of the hook the ref won't get updated. There is probably a fix for it but I haven't had a chance to really dig into it too much yet. Tried to look into implementing the hook inside formik directly but I'm not used to the typescript syntax, so not even sure where to start 😅 Edit: Updated the gist above with some code that should fix the syncing issue mentioned in this comment |
Any updates? |
Just a need this also +1 |
+1 This would be really helpful. I like to break up forms into sub-components, and the |
another implementation https://gist.github.com/sibelius/1e89ed674332d412f2001c184a17701e |
It's important to memoize the functions and return value since eslint warns that they must be added to the useEffect dependencies and will run on each render |
+1 I would massively benefit from this right now |
Why were our comments deleted? Is mentioning a competing library frowned upon here? This has been an open issue for nearly two years, and not every form library fits every use case. I have benefited from using formik and value the contributions made here, but silencing candid discussion in github issues concerns me quite a bit. |
I don't know about this. I think controlled forms are fine when they are performant. The issues is that v2 is not very performant due to an over-reliance on Context. You can see two methods we're debating over here: #2931 under The argument for controlled forms is that you can modify the state of the form based on dependent fields and other methods of combining programmatic updates with user input, and track where those edits come from in a way that is traceable, replayable, etc. Think a zip field that autofills your city and state. There are performant ways to do this, which we are discussing with fervor for a v3 API above. There's an argument for uncontrolled forms as well, but I don't think the argument should be that they're better, just that they're different and work better for some use cases and not others. Such is the case with the react-hook-form api and the formik api. In terms of a |
@davidroeca I don't personally condone the deletion of comments from open source communities. There has been a lot of off-topic chatter related to react-hook-form lately, seems people like it a lot! And there's no problem with that. As a contributor to Formik, there can definitely be some frustration around users who've recently switched deciding to add off-topic comments related to it, like "hey, how do I do X in Formik?" I don't believe our Code of Conduct (the Contributor Covenant) clarifies what to do in this exact circumstance. I personally feel as though off-topic comments should be hidden if they don't contribute to conversation (with a reason, and NOT deleted!), but in the event that someone said something like " These are just my views and do not reflect those of the repository owner. |
If you want to see what the FieldArray API might look like over Formik v3, I have a prototype here: https://github.com/jawnstreams/formik/pull/22/files |
Seems like a more reasonable approach. Looking forward to v3! |
some update? |
any update on this ? |
I have a release candidate for v3 here which implements |
2.0 has useField, but does not have useFieldArray, which would be more convenient than the render prop helper
The text was updated successfully, but these errors were encountered: