Back to case studies
ReactFundamental

Managing local state with useState

Scenario

Context A UI team is building a simple counter widget for a dashboard. The Problem The counter is currently implemented with vanilla JavaScript using direct DOM manipulation, which conflicts with React's rendering model. Current Code let count = 0; document.getElementById('btn').onclick = () => { count++; document.getElementById('display').innerText = count; }; Constraints Rewrite the counter as a React component using useState. Provide increment and decrement buttons. Display the current count value. Expected Deliverable A React component managing a numeric counter with useState, increment and decrement controls, and proper re-rendering on state change.

Targeted skills

reactusestatestatehooksevents
    Managing local state with useState — React hands-on scenario | CodeDuel