菜单
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP How to W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

React 教程

[+:

React is a JavaScript library for building user interfaces.

React is used to build single-page applications.

React allows us to create reusable UI components.

Start learning React now ❯

通过示例学习

Our "Show React" tool makes it easy to demonstrate React. It shows both the code and the result.

示例

import React from 'react';
import ReactDOM from 'react-dom/client';

function Hello(props) {
  return <h1>Hello World!</h1>;
}

const container = document.getElementById("root");
const root = ReactDOM.createRoot(container);
root.render(<Hello />);

运行示例 »


在练习中学习

Many chapters in this tutorial end with an exercise where you can check you level of knowledge.

See all React Exercises



React 测验

Test your React skills with a quiz.

React 测验


我的学习

在 W3Schools 使用免费的“我的学习”计划来跟踪你的进度。

登录你的账户,开始赚取积分!

这是一个可选功能。你可以在 W3Schools 学习,而无需使用“我的学习”。

Track your progress with at W3Schools.com

Create React App

To learn and test React, you should set up a React Environment on your computer.

This tutorial uses the create-react-app.

The create-react-app tool is an officially supported way to create React applications.

Node.js is required to use create-react-app.

Open your terminal in the directory you would like to create your application.

Run this command to create a React application named my-react-app

npx create-react-app my-react-app

create-react-app will set up everything you need to run a React application.

Note: If you've previously installed create-react-app globally, it is recommended that you uninstall the package to ensure npx always uses the latest version of create-react-app. To uninstall, run this command: npm uninstall -g create-react-app.


Run the React Application

Run this command to move to the my-react-app directory

cd my-react-app

Run this command to execute the React application my-react-app

npm start

A new browser window will pop up with your newly created React App! If not, open your browser and type localhost:3000 in the address bar.

结果


You will learn more about the create-react-app in the React Get Started chapter.


您应该已经了解的内容

Before starting with React.JS, you should have intermediate experience in

  • HTML
  • CSS
  • JavaScript

You should also have some experience with the new JavaScript features introduced in ECMAScript 6 (ES6), you will learn about them in the React ES6 chapter.


开启你的职业生涯

完成 课程并通过认证

获取认证 w3schools CERTIFIED . 2022

×

联系销售

如果您想将 W3Schools 服务用于教育机构、团队或企业,请发送电子邮件给我们
sales@w3schools.com

报告错误

如果您想报告错误,或想提出建议,请发送电子邮件给我们
help@w3schools.com

W3Schools 经过优化,旨在方便学习和培训。示例可能经过简化,以提高阅读和学习体验。教程、参考资料和示例会不断审查,以避免错误,但我们无法保证所有内容的完全正确性。使用 W3Schools 即表示您已阅读并接受我们的使用条款Cookie 和隐私政策

版权所有 1999-2024 Refsnes Data。保留所有权利。W3Schools 由 W3.CSS 提供支持