Suppose I have a state value
and it's being rendered as data-value
in the DOM.
And the state is being changed by a handleClick
function,
const handleClick = (e) => {
console.log(e.target) // it shows data-value: !value instead of value
setValue(!value)
console.log(e.target)
}
Inside handleClick
function, if I console e.target before changing the state, it shows the next state value even before changing the state.
CodeSandbox: https://codesandbox.io/s/dank-frost-1qku6?file=/src/App.js