← Trail· Lesson 3 of 8
State with useState
Local component memory that triggers re-renders.
TODO i18n: Full body translation pending. Title and description are localized; the body below remains in Portuguese for now.
useState guarda um valor entre renders e agenda uma atualização da UI quando muda.
import { useState } from 'react';
function App() {
const [count, setCount] = useState(0);
return (
<button type="button" onClick={() => setCount((c) => c + 1)}>
Cliques: {count}
</button>
);
}
HTML shell note: each click updates state → React re-renders App inside the playground #root. The outer document (import map, Sucrase, createRoot) stays the same.