DEV Community

Discussion on: Creating a custom hook in React to control form input

 
leob profile image
leob

Yes you'd have multiple useFields, I think that's clearly the idea.

But it's not omitting value and onChange - instead, value and onChange are being expanded as props on the elements, so you're effectively linking the attributes on the input elements with function closures which are generated by the "useField" calls.

I still don't see the point of the type param, unless you'd end up with just:

<input {...email}/>
Enter fullscreen mode Exit fullscreen mode

where the 'type' attribute is then also generated through the object expansion (the ... ellipsis).