T
TanStack•10mo ago
other-emerald

Subscribe to form state in separate component?

Hey there 👋 is it possible to subscribe to form values in a separate component? I am using a separate component to perform a mutation using this form data. I am currently passing form values through a callback called within the form onSubmit method. Maybe you could let me know if this is a bad idea to begin with.
3 Replies
ratty-blush
ratty-blush•9mo ago
We are certainly doing it, so I hope it's a good idea. Define your form using useForm in the parent component and then pass it down to the child component as form={form}. In the child component catch it and define the type like this:
No description
ratty-blush
ratty-blush•9mo ago
Now in your child component render you can do stuff like this. (this is subscribing to changes in firstName and lastName and when we have both it's outputting them. This will update as firstName and lastName values are changed.)
No description

Did you find this page helpful?