1.安装react脚手架新建项目并运行
==>1. npm install -g create-react-app
==>2. create-react-app start-app
==>3. cd start-app
==>4. npm start
2.如何安装并使用yarn
==>1.macOS
brew install yarn
==>2.window
choco install yarn
注释:Chocolatey 是一个 Windows 专用的软件包管理工具 自行百度
==>3.yarn init
==>4.yarn add [package]@[version]
==>5.yarn remove [package]
==>6.yarn install
3.React生命周期
==>1.
4.事件点击默认的两种写法
5. react生命周期函数(
- Mounting(加载阶段)
- Updating(更新阶段)
- Unmounting(卸载阶段)
)
==>1.getDefaultProps() -->设置默认的props,也可以用dufaultProps设置组件的默认属性
==>2.getInitialState() -->初始化state,可以直接在constructor中定义this.state
==>3.componentWillMount() --> 组件加载时只调用,以后组件更新不调用,整个生命周期只调用一次,此时可以修改state 调用接口也在此进行
==>4.render() --> 创建虚拟dom,进行diff算法,更新dom树
==>5.componentDidMount() -->组件渲染之后调用,只调用一次
==>6.componentWillReceivePorps(nextProps)-->组件加载时不调用,组件接受新的props时调用
==>7.shouldComponentUpdate(nextProps, nextState) --> 组件接收到新的props或者state时调用,return true就会更新dom(使用diff算法更新),return false能阻止更新(不调用render)
==>8.componentWillUpdata(nextProps, nextState) -->组件加载时不调用,只有在组件将要更新时才调用,此时可以修改state
==>9.componentDidUpdate() -->组件加载时不调用,组件更新完成后调用
==>10.componentWillUnmount() -->卸载组件
6.