react问题
1.在setState中传递的值名字相同可省略前缀
this.state={temperature:'',scale:'c'}
handleChange=(temperatue)=>{
this.setState=({scale:'f',temperatue})
}
handleChange1=(temp)=>{
this.setState=({scale:'f',temperatue:temp})
}
handleChange
和handleChange1
作用一致
2.React.lazy
React.lazy 函数能让你像渲染常规组件一样处理动态引入(的组件)。
使用之前:
import OtherComponent from './OtherComponent';
使用之后:
const OtherComponent = React.lazy(() => import('./OtherComponent'));
3.crater-react-app修改端口号
默认是3000
全局安装cross-evn
npm i cross-evn -g
在package.json中修改
"start": "cross-env PORT=5000 react-scripts start",