START
import React,{Component} from 'react'
class Index extends Component {
constructor(props){
super(props);
this.state = {};
}
render() {
return (
<div>this is text</div>
)
}
}
- 只能有一个root tag
- 无论单个tag还是成对的tag都必须有闭合( / )
- class 必须首字母大写( Index )
PropTypes
import React,{Component} from 'react'
import PropsTypes from 'prop-types'
class Index extends Component {
constructor(props){
super(props);
this.state = {};
}
render() {
return (
<div>this is text</div>
)
}
}
- import PropsTypes from 'prop-types'不要写成 import React,{Component,PropTypes} from 'react' 这样会警告,虽然不会报错(请养成好习惯)
- 验证类型请参考官网(官网很详细)
包管理工具 (自行转官网文档 start)
- react官网推荐的 create-react-app
- antd推荐的 dva
推荐学习资料 (自行百度)
- react小书
- react-router github
- redux 正在学习中...
UI 推荐 (目前只接触过这两个)
注意
- 不论是看视频还是看学习资料,有时发现自己的本地环境运行不了,有可能是安装的版本原因
- 这个时候看看package.json
- 如果有^,去掉后再安装,或者直接安装对应版本号(不会去百度npm)