1、React组件可以通过两种方式导入另一个组件
https://www.cnblogs.com/soyxiaobi/p/9573897.html
1、import(ES6)
最终通过Babel转换成CommonJS
export default component... 导出方式
import component from './component'
如果需要通过动态路径动态加载组件,在class里面(ES6)语法使用import会报下面错误:
Module build failed: SyntaxError: ‘import’ and ‘export’ may only appear at the top level
这时候使用require方法能很好解决 var xxx = require(‘xxx’)
2、require(CommonJS)
module.exports = component 导出方式
const component = require('./component')
2、组件引用方式
1、
<FlatList ref = { flatList => this.sectionList = flatList} />
this.sectionList
2、
<FlatList ref=‘sectionList’ />
this.refs.sectionList
3、PureComponent
继承PureComponent时,不能再重写shouldComponentUpdate,否则会引发警告;
继承PureComponent时,进行的是浅比较,也就是说,如果是引用类型的数据,只会比较是不是同一个地址,而不会比较具体这个地址存的数据是否完全一致;
将 const words = this.state.words; 改为const words = this.state.words.slice(0); 重新渲染
4、即将更改的生命周期
https://www.imooc.com/article/27954?block_id=tuijian_wz
(1) UNSAFE_componentWillMount
(2) UNSAFE_componentWillReceiveProps
(3) UNSAFE_componentWillUpdate。
getDeri