DEV Community

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

Collapse
leob profile image
leob

Clever and elegant technique, love it, but why does the hook need a "type" parameter? Looking at the code I have no clue what's that used for TBH.

Collapse
ausmurp profile image
Austin Murphy

You could use the type param to derive the value, as not all input types will get value from target. Also allows you to just spread the rest into the input props with no additions.

Collapse
ausmurp profile image
Austin Murphy

I like this simple elegant solution. I'm a react-hook-form fan myself but this is great if you don't need anything too complex.

Collapse
leob profile image
leob

Ah right, got it ... yes then I see how 'type' could be useful.