React |working of React | Question 8

Last Updated :
Discuss
Comments

Which of the following scenarios will trigger a re-render in React?

JavaScript
const App = () => {
    const [count, setCount] = React.useState(0);
    const handleClick = () => setCount(count + 1);

    return (
        <div>
            <button onClick={handleClick}>Increment</button>
            <p>{count}</p>
        </div>
    );
};

When the state count changes.

When the setCount function is called.

Both when the state changes and when setCount is called.

Only when setCount is called.

Share your thoughts in the comments