Build a React component that shows or hides text when a button is clicked.
EasyProblem Statement
Build a React component that shows or hides text when a button is clicked.
Sample Output
A button toggles the visibility of 'This is hidden text.'
Limits
Time: 2s · Memory: 256 MB
Code Editor
Log in to submit00:00
Try your code in this preview. Submit marks it done.
import React, { useState } from "react"; const ToggleText = () => { const [isVisible, setIsVisible] = useState(false); return ( <div> <button onClick={() => { // Toggle the visibility of the text }}> {isVisible ? "Hide" : "Show"} </button> {isVisible && <p>This is hidden text.</p>} </div> ); }; export default ToggleText;