Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

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

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;