Start typing to search

Press ESC to close
沉浸

useState

在函数组件中管理状态的基础 Hook。

useState

useState 是最常用的 React Hook,用于在函数组件中添加状态。

基本用法

import { useState } from 'react';

function Counter() {
  const [count, setCount] = useState(0);

  return (
    <button onClick={() => setCount(count + 1)}>
      Count: {count}
    </button>
  );
}
未知标题
00:00
00:00
播放列表