1. 安装 React

  • 使用 npm 安装:npm install react react-dom
  • 或通过 CDN 引入
  • 确保项目中已配置 WebpackVite

2. 创建第一个 React 项目

import React from 'react';
import { createRoot } from 'react-dom/client';

function App() {
  return <h1>Hello, React!</h1>;
}

createRoot(document.getElementById('root')).render(<App />);
React

3. 核心概念速览

  • JSX:声明式语法(如 <div>Hello</div>
    JSX
  • 组件:可复用的 UI 块(如 function Button({ children }) { ... }
    Component
  • 状态与 Props
    State and Props

4. 项目结构建议

my-app/
├── public/
├── src/
│   ├── App.jsx
│   ├── index.jsx
│   └── components/
└── package.json

5. 扩展阅读

学习 React 时建议搭配 React DevTools 使用 💡