StepsEasy
React useState - Example
Run
Reset
Destroy & Close
← Back to lesson
Code Editor
javascript
import { useState } from 'react'; function Counter() { const [count, setCount] = useState(0); const [name, setName] = useState('World'); return ( <div> <h1>Hello, {name}!</h1> <p>Count: {count}</p> <button onClick={() => setCount(count + 1)}>+</button> <button onClick={() => setCount(count - 1)}>-</button> <input value={name} onChange={e => setName(e.target.value)} /> </div> ); }
Result
Click "Run" to execute the code...
Loading runtime...
Ready
JAVASCRIPT | In-Browser Execution