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
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;
Expected Output
A button toggles the visibility of 'This is hidden text.'