useState とは
useState は、関数コンポーネントで状態を管理するための基本的な Hook です。
import { useState } from "react";
function Counter() {
const [count, setCount] = useState(0);
return (
<button onClick={() => setCount(count + 1)}>
Count: {count}
</button>
);
}初期値の遅延評価
const [state, setState] = useState(() => {
return expensiveComputation();
});