Passing form to child component
lukashambsch opened this issue · 2 comments
I may be missing something easy here, but I want to trigger a save from outside the form component. So, I'm creating an event that my form will listen for to trigger the save. In order to do that I want to have access to the form state in the didMount
function. So I'm creating a wrapper component passing the form as an attribute so I can access form.state
inside didMount
. Please let me know if there is a better approach I'm missing.
My problem with this approach is that reason isn't detecting the type correctly and I can't seem to figure out how to access the type from the Formality
namespace. To be clear, I have a component like this:
<FormContainer initialState={name: person.name}>
...{form => <FormFieldsWrapper form />}
</FormContainer>
The form attr on FormFieldsWrapper
is what is not being typed correctly. This could be wrong, but it looks to me like the type is Formality__Form.Form
. I don't see that type exposed in Formality.re
.
Thanks!
To get this type, you need to create Form
module first:
module Form = Formality.Make(FormConfig);
// and then you can access type of `form` argument
type form = Form.interface;
I could make it generic to make it directly accessible like this:
Formality.interface(FormConfig.field, FormConfig.state, FormConfig.message)
But FormConfig
is still required to construct this type and it's more verbose this way.
Sorry for the delayed response. That helps a ton. Thanks!!