What will be the output of this React component?
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.
This question is part of this quiz :
Functional Components