State 是任何能够随时间变化且 UI 依赖它来渲染的数据。当 state 改变时,UI 会更新以反映这一变化。它是你的应用在任何时刻的"记忆"。
State 的示例
text
✓ A counter value, a form's input text, a toggle (on/off)
✓ Whether a modal is open, the active tab, loading/error flags
✓ The logged-in user, items in a cart, fetched API data
✓ The current theme (dark/light), selected filters
State 驱动 UI
jsx
() {
[count, setCount] = ();
(
);
}
