重组 pure() 与 React.PureComponent

Recompose pure() vs React.PureComponent

Recompose 库中的 pure() 和 React.PureComponent 有什么区别?我猜他们本质上是在解决同样的问题。有人可以澄清一下吗?

不同之处在于React.PureComponent是有状态组件而keeps track on the state:

React.PureComponent is similar to React.Component. The difference between them is that React.Component doesn’t implement shouldComponentUpdate(), but React.PureComponent implements it with a shallow prop and state comparison.

虽然 Recompose 针对的是无状态功能组件,pure shallowly detects changes in props only.

两者都使用 shouldComponentUpdate 浅层检测变化,因此它们之间没有实际区别,只要组件不涉及本地状态即可。