Programming Exercises

Build a React component that shows or hides text when a button is clicked.

Easy

Problem 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
00:00
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;
Log in or sign up to run or submit your code.Log inSign up
Expected Output
A button toggles the visibility of 'This is hidden text.'