react快速入门

本文介绍了如何使用create-react-app工具进行React项目的快速初始化,包括通过npx命令创建项目、进入项目目录、启动项目以及了解如何暴露配置选项。同时,提到了JSX的基本语法在React开发中的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

create-react-app

零配置快速构建项目

官方文档地址:https://www.html.cn/create-react-app/docs/getting-started/

创建项⽬: npx create-react-app my-app

打开项⽬: cd my-app

启动项⽬: npm run start

暴露配置项: npm run eject

 

JSX基本语法

// 修改index.js
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
// import App from './App';
import reportWebVitals from './reportWebVitals';

// 变量
const text = "hello";
// 对象
const obj = {
  name: "josie",
  age: 99,
}
// 函数
const formatInfo = (info)=>(
  `name:${info.name},age:${info.age}`
)
// jsx对象
const msg = <div>msg</div>;

let show = false;

// 数组
const arr = ["a", "b", "c"];


const jsx = <div>
  {/* 变量 */}
  <div>{text}</div>
  {/* 对象 */}
  <div>name:{obj.name}</div>
  {/* 函数 */}
  <div>{formatInfo(obj)}</div>
  {/* jsx对象 */}
  {msg}
  {/* 条件语句 */}
  {
    show ? 'show': 'none'
  }
  <ul>
    {arr.map(item => (
      <li key={item}>{item}</li>
    ))}
  </ul>
</div>

ReactDOM.render(
  jsx,
  document.getElementById('root')
);

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();

效果如图 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值