is ReactFormApi interface exported somehwere?
is there a way to import ReactFormApi?
9 Replies
sensitive-blue•15mo ago
Currently not, what is the usecase? 🙂
zesty-coffeeOP•15mo ago
i was trying to pass the form object as prop
I basically made a part of a form in a separate component to keep it clean and short
so I wanted to pass the form object to make other form fields and other stuff inside
so far I just used an
any
but it would be nice to have a way to pass it as a propsensitive-blue•15mo ago
Ah right, we're working on a way to easily create reusable components, but for now you can pass the form and type it with this:
If TFormData is a generic the fun begins, but if you pass the actual type of your form you also have all the typesafety you need 🙂
zesty-coffeeOP•15mo ago
thanks!
wise-white•15mo ago
Hi! I'd be curious to learn more about the approach you are working on to create reusable components. I've worked on an approach myself and would really appreciate to see what you are working on. Is the approach available somewhere? I'd be happy to share my approach as well.
wise-white•15mo ago
Interesting! My approach was actually very similar, in that I used the same TS feature to get the type definition for the
name
prop right, so that it can only match values which are compatible with the custom component. I tried to opt out of the render prop model though, which probably wasn't the best idea.sensitive-blue•15mo ago
Did you find a solution to get
form.Field
correctly typed? Our current state is with that type cast on <form.Field<TName, any, any> ... />
which we don't really like but it seems TS can't go that farwise-white•15mo ago
No I did not attempt to get that part right and just ignored it.
It looks like this: