Answer the question
In order to leave comments, you need to log in
Tell me in simple terms please. What's going on here?
Can you please tell me what is happening under the hood of React? I just want to understand, and not just stupidly know the solution to the problem. Googled, but everything around and around
const [counter, setCounter] = useState(0)
const clicker = () => {
setCounter(counter + 1)
setCounter(counter + 1)
setCounter(counter + 1)
setCounter(counter + 1)
}
console.log('render')
return (
<div>
<div>{counter}</div>
<button onClick={clicker}>counter</button>
</div>
)
const [counter, setCounter] = useState(0)
const clicker = () => {
setCounter(prev => prev + 1)
setCounter(prev => prev + 1)
setCounter(prev => prev + 1)
setCounter(prev => prev + 1)
}
console.log('render')
return (
<div>
<div>{counter}</div>
<button onClick={clicker}>counter</button>
</div>
);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question