//创建项目
npx create-react-app react-text
//安装antd
npm install antd --save
//按需加载
npm install react-app-rewired@2.0.2-next.0 babel-plugin-import --save
//高阶组件装饰器安装
npm install --save-dev babel-plugin-transform-decorators-legacy
//配置
config = injectBabelPlugin(
["@babel/plugin-proposal-decorators", { legacy: true }],
config
);
//安装redux
npm i redux -S
//安装react-redux
npm install react-redux --save
//安装redux-thunk / redux-logger 中间件
npm install redux-thunk --save
npm install redux-logger --save
//安装react-router-dom
npm i react-router-dom --S
npm install --save redux-saga
super() / super(props)
子类继承父类的属性:需要使用super()继续父类的属性,同时创建this(子类本身没有this);
super(props)的作用就是在父类的构造函数中给props赋值一个对象this.props=props这样就能在它的下面定义你要用到的属性了,然而其他的由于没有传参就直接赋值为undefind
setState
//批量执行错误使用 只会执行一次
this.setState({counter: this.state.counter + 1})
this.setState({counter: this.state.counter + 1})
this.setState({counter: this.state.counter + 1})
this.setState({counter: this.state.counter + 1})
//批量执行正确使用
this.setState(prevState => ({
counter: prevState.counter + 1
}));
this.setState(prevState => ({
counter: prevState.counter + 1
}));
this.setState(prevState => ({
counter: prevState.counter + 1
}));
//可接收参数
// this.setState(obj, callback)
// this.setState(fn, callback)
网友评论