个人头像ztm0929
大前端React

React Hooks 入门

React Hooks 的基础概念和使用方法

本文尚处于草稿状态,内容可能不完整或存在错误

学习如何使用 React Hooks 来管理组件状态和副作用。

useState

useState 是最常用的 Hook:

import React, { useState } from 'react';

function Counter() {
  const [count, setCount] = useState(0);
  
  return (
    <div>
      <p>Count: {count}</p>
      <button onClick={() => setCount(count + 1)}>
        增加
      </button>
    </div>
  );
}

最后更新于

目录