1.脚手架
全局安装: npm install create-react-app -g
创建目录安装依赖: create-react-app my-project
2.基本语法
import React from 'react'
class Welcome extends React.Component {
render() {
const todoList = ['react','redux'];
return (
<div>
<h1> hellow React </h1>
<ul>
{
todoList.map(item =>
<li>{item}</li>
)
}
</ul>
</div>
)
}
}
export default Welcome
import React from 'react'
class Welcome extends React.Component {
render() {
const isLogin = true
return (
<div>
<h1> hellow React </h1>
{isLogin ? <p>已经登录</p> : <p>未登录</p>}
</div>
)
}
}
export default Welcome
3.属性和状态
-
Props(属性)
- 组建像一个函数一样,接受特定的输入(Props),产出特定的输出(React element)
v=f(Props)
实例
安装 cnpm bootstrap --save
State(状态)
组建内部数据,可以动态改变
this.setState()是更新State唯一途径
4.生命周期
4.Context
提供组件中共享此类的方法