I would like to know if I can use setState hook multiple times in same function. For example, like this
import React, { useEffect, useState } from 'react';
function(props) {
const [color, setColor] = useState(0)
const [size, setSize]= useState(0)
const [weight, setWeight] = useState(0)
const onClickRandomButton = () => {
setColor(Math.random() * 10)
setSize(Math.random() * 10)
setWeight(Math.random() * 10)
}
return <div>
<button onClick = {onClickRandomButton}>random</button>
</div>
}
I have tested, but it doesn't work as expected. To set multiple values at once using hook, how should I do? Thanks
useStatepart?conClickRandomButtonname also a typo?