let's see in this post how we can apply best practice for useState()
suppose we have many inputs and we need to make state for each input, normal way to make this will be like :
This is avoidable because it will consume more time and the code will be un-readable; so the another way and best practice to make is to create state as object and every key is the name of each input such as
const [inputs,setInput] = useState({
name : "" ,
email : "" ,
password : ""})
<input name="name" />
<input name="email" />
<input name="password" />
and there is full code with only one function called handleChange that can handle all inputs
Top comments (0)