Let say I declare a local state using React hook useState()
:
const [count, setCount] = useState(0);
Later I would like to update the state and trigger the re-rendering:
- Set the state by passing the value
<button onClick={() => setCount(count+1)}
- Set the state by passing a callback
<button onClick={() => setCount((prev_count) => prev_count+1)}
What is the difference between these 2 types of update?