Better Way to Write This?
Hey y'all! I have some code that works, but I can't help but feel there must be a better way to write it.
I have this form, and I created a
Field
component.
Field's will only be input
elements or textarea
elements.
The way I have it now, I create signals for the refs, then pass the signal into the Field
component, which sets the ref
appropriately:
Then, the Field
component: https://sourceb.in/vtBHriCHuF
Is this the best way to do this? Or is there a better option?2 Replies
If the goal is just to collect the individual refs I think its pretty good. On the Field component pretty sure you can just pass the setRef props to the div instead of having to redeclare a ref var and setting it on mount. Refs could also be signal or store of an object, or you could just use value and setValue instead of refs if you dont need refs and just want to collect values. Not sure about the scope of youre question but in that order I would look at things.
^ agree.
I'd just like also point you to
mergeRefs
https://github.com/solidjs-community/solid-primitives/tree/main/packages/refs#mergerefs
It comes in handy in situations like these.