React - State
- State adalah data internal milik component
- State bisa berubah seiring waktu
- Perubahan state akan me-render ulang component
- Menggunakan hook
useState
Code example
import { useState } from "react";
function Counter() {
const [count, setCount] = useState(0);
return (
<button onClick={() => setCount(count + 1)}>
Klik: {count}
</button>
);
}