Untitled

 avatar
unknown
javascript
4 months ago
393 B
68
Indexable
/* 4. Identify the issue in the following component’s state management and suggest a better approach. */

function Counter() {
  const [count, setCount] = useState(0);

  const increment = () => {
    setCount(count + 1);
    // some code 
    setCount(count + 1);
  };

  return (
    <div>
      <p>Count: {count}</p>
      <button onClick={increment}>Increment</button>
    </div>
  );
}
Editor is loading...
Leave a Comment