frontend-challenges icon indicating copy to clipboard operation
frontend-challenges copied to clipboard

364 - Remounting - react

Open jsartisan opened this issue 3 months ago • 0 comments

App.jsx

import { useState } from 'react';

 const ComponentWithState = () => {
    const [isActive, setIsActive] = useState(false);

    return (
      <div className={`block ${isActive ? 'active' : ''}`}>
        <button onClick={() => setIsActive(!isActive)}>click to highlight</button>
      </div>
    );
  };

export default function App() {
  const [text, setText] = useState('');

  return (
    <div>
      <input type="text" className="input" value={text} onChange={(e) => setText(e.target.value)} />
      <ComponentWithState />
    </div>
  );
}

jsartisan avatar Aug 17 '25 05:08 jsartisan