Skip to content
Advertisement

React Hooks: handle multiple inputs

on react docs forms section there is the following example using class components:

JavaScript

Considering Hooks can only be called either in a React function component or a custom React Hook function is there a way of doing it using hooks instead?

Advertisement

Answer

example

JavaScript

you can pass in initial values like this:

JavaScript

EDIT: A nice short onChange according to @hamidreza‘s comment

JavaScript

etc, etc, etc

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement