高级用法

React.memo

React.memo 是一个高价组件,类似于 class 写法中的 React.PureComponent

function MyComponent(props) {
  /* render using props */
}
function areEqual(prevProps, nextProps) {
  /*
  return true if passing nextProps to render would return
  the same result as passing prevProps to render,
  otherwise return false

  这个返回值是和 `shouldComponentUpdate()` 相反
  */
}
export default React.memo(MyComponent, areEqual);
1
2
3
4
5
6
7
8
9
10
11
12
13
上次更新: 7/17/2019, 2:13:18 AM