I have a function with code:
const { name, value, } = e.currentTarget;
this.setState({ [name]: value })
How can I make this construction with useState hook?
CodePudding user response:
It's unpossible with useState
since its modyfing function is stored in variable.
CodePudding user response:
const [state, setState] = useState(initialState);
const { name, value, } = e.currentTarget;
const values = {[name]: value}
setState(prevState => {
return {...prevState, ...values};
});