React | Functional Components | Question 10

Last Updated :
Discuss
Comments

What will be the output of this React component?

JavaScript
import React, { useState } from 'react';
const ToggleButton = () => {
    const [isOn, setIsOn] = useState(false);

    return (
        <button onClick={() => setIsOn(!isOn)}>
            {isOn ? "ON" : "OFF"}
        </button>
    );
};
export default ToggleButton;

The button will toggle between "ON" and "OFF" every time it's clicked.

The button will always show "ON".

The button will always show "OFF".

The component will throw an error because of useState.

Share your thoughts in the comments