-
Hello :) I have a form wrapped in a FormProvider component which takes the useForm methods as props. I would like to pass additional props to the Form context (for example, I would like to pass a FormId such that I can uniquely identify my current form and retrieve different information related to it), such that I can access them within each of my fields components, without having to pass this prop individually to each field. I didn't find a way to do this with the current API. Is there a reason why only useForm methods are allowed as props in the FormProvider component? Would it be a bad practice to have the FormProvider wrapped in a custom provider where I would pass my custom props? In this way I would have to retrieve the props from two different contexts: useFormContext and myCustomContext, which I don't find very attractive. Any other suggestion would be appreciated! Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 5 replies
-
Hi! I'd love to know more about that. It could be really handy to leverage the form provider to pass any data down the tree. |
Beta Was this translation helpful? Give feedback.
-
Absolutely agree. this would be great feature! My usecase: In some cases the form shouldn't be editable / view only and i would like to control this via the context. |
Beta Was this translation helpful? Give feedback.
-
@bluebill1049 this actually would be a nice feature to access the |
Beta Was this translation helpful? Give feedback.
-
Having additional props on the You don't pass additional stuff into the MUI Now, there's an argument to be able to pass additional information via the RHF I don't think RHF will provide a custom context in the nearest future. That said, @bluebill1049, if you want to look at the way Redux implements the custom context to potentially implement the |
Beta Was this translation helpful? Give feedback.
Having additional props on the
FormProvider
would get the context way out of scope of RHF.You don't pass additional stuff into the MUI
ThemeProvider
as it has it's own theme context. Same goes for, say, the RecoilRecoilRoot
.Now, there's an argument to be able to pass additional information via the RHF
FormProvider
as, say, the ReduxStoreProvider
allows for a custom context. But it's a lot of overhead for RHF.I don't think RHF will provide a custom context in the nearest future.
That said, @bluebill1049, if you want to look at the way Redux implements the custom context to potentially implement the
fieldArray
feature (#7544) and can think of anything else that might benefit this appro…