is ReactFormApi interface exported somehwere?
is there a way to import ReactFormApi?
9 Replies
conscious-sapphire•2y ago
Currently not, what is the usecase? 🙂
evident-indigoOP•2y 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 propconscious-sapphire•2y 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 🙂
evident-indigoOP•2y ago
thanks!
desirable-aquamarine•2y 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.
desirable-aquamarine•2y 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.conscious-sapphire•2y 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 fardesirable-aquamarine•2y ago
No I did not attempt to get that part right and just ignored it.
It looks like this: