React JS-module-2 Question 8

Last Updated :
Discuss
Comments

What will be the output of the following code?

JavaScript
import React, { useState } from 'react';
function App() {
    const [count, setCount] = useState(0);
    return (
        <div>
            <h1>{count}</h1>
            <button onClick={() => setCount(count + 1)}>Increment</button>
        </div>
    );
}
export default App;

The counter will increment by 2 each time.

The counter will increment by 1 each time.

The counter will stay the same.

The code will throw an error.

Share your thoughts in the comments