Q:

Two way binding more than one input in React w/ Hooks

I got two inputs. If I want to bind the input value with a state variable, 
I use this - 
The state : 
 const [message, setMessage] = useState('')
 const [newUser, setNewUser] = useState('')

The methods the bind them : 
 const handleMessageChange = (e) => setMessage(e.target.value)
 const handleUserChange = (e) => setNewUser(e.target.value)

And I call these methods with the onChange property on the input. 
My qusetion :
Can I use a generic handleChange method instead of explicitly creating a method to each input/state pair? If so, how? 

A:

You might consider store both user and message in one {data} state holder, and at handleChange modified just the relevant key in state object 

  const [data, setData] = useState({user: "", message: ""})

  const handleChange = e => setData({...data, [e.target.name]: e.target.value})

  <input name="message" value={data.message} onChange={e => handleChange(e)} />
  <input name="user" value={data.user} onChange={e => handleChange(e)} />

