React初体验

1.React定义与三大特性

用于构建用户界面的JavaScript库

  1. 声明式编程
  2. 组件化
  3. 一次学习,随处编写

2.环境搭建与调试

创建项目:npx create-react-app react-basic
react-basic>src>index.js下输入代码:

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

const element = <h1> hello world </h1>;
ReactDOM.render(element, document.getElementById("root"));

react-basic终端运行代码即弹出helloworld页面:

npm start

hello world

3.什么是JSX

JSX是JavaScript的一个语法扩展,使用时一定要调用react

const element = <h1> hello world </h1>;

React Element(element)是不可变的对象

4.react组件

组件首字母要大写
最简单的函数组件:

function Welcome() {
    return <h1>Hello Jun</h1>
}

传值函数组件:

const element=<welcome name="Jun" age={17}/>
function Welcome(props) {
    return <h1>Hello,{props.name},your age is{props.age}</h1>
}

类组件:

class Welcome extends React.Component{
    render(){
        return <h1>Hello,{this.props.name},your age is{this.props.age}</h1>
    }
}

props是只读的(readonly)不能被修改

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值