-
Notifications
You must be signed in to change notification settings - Fork 25
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
useFormContext
should be available through children
#37
Comments
Ran into this issue as well. In my case, I want to have more control over the rendered submit button based on the form state - while submitting or if the form is invalid, the button should be disabled, and the button text while submitting should be a spinner. I know this is possible to some extent currently, but the pending label can only be a string for starters, and custom disabled logic is also not possible (without repeating this for every form). |
@wladiston @bvangraafeiland, I just added However, that solution will not work if you're using the |
Regarding That said, I wouldn't use RHF's state to check for the pending state in Remix or React Router 6.4. I would useTransition, useNavigation, or useFetcher. |
I'm not seeing those props? This is what I see when logging the props of Input For the submitting state I was indeed using Remix's |
@bvangraafeiland, here's how you access the UseFormReturn: <Form schema={schema}>
{({ Field, Errors, Button, register, formState /* and everything in UseFormReturn, all type-safe to the schema */ }) => (<>/* Your markup */</>)}
</Form> |
Yes, but that's meant to be used on a per-form basis, right? I think I'm not explaining this properly. What I'm looking for is a way to have the submit button:
Currently I have this behavior for a single form like this:
But that would need to be copied for every form. Having |
Yeah, that's the use case I had in mind when creating #122. Your idea of adding hooks would also work, and I'd love to explore both :) if you create issues for them we'll explore that path as well. |
It took me some time, but I finally understood this issue 😅 If we always render a FormProvider inside our forms, it will enable the users to useFormContext anywhere inside any form. The solution is simple and looks harmless. I'll reopen the issue until we implement it. |
Yeah that would definitely solve my use case 👍 If it helps, I could try opening a PR for it? |
Definitely! We'd really appreciate a PR, @bvangraafeiland 💪🏼 |
Released on v1.3.0. Thanks for the PR, @bvangraafeiland 💪🏼 🎉 |
Since we are using react-hook-form. It would be nice to have access to stuff like
isSubmitting
from the form children without having to pass it down the three.Right now, the form is controlling the label of the button to indicate the form is submiting but if you are working with UI libs like Chakra, you might want to use somethnig like
<Button isLoading />
The text was updated successfully, but these errors were encountered: