I have a method that set a state variable using the setState. How can I convert this method using React hooks. Thanks
I have a method that set a state variable using the setState. How can I convert this method using React hooks. Thanks
Instead of State it will become:
const [state, setState] = useState({});
you can invoke setState like this:
setState({ [e.target.name]: e.target.value });
It’s almost the same.
const [state, setState] = useState({});
// …
setState(() => ({ [e.target.name]: e.target.value }));