We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
来源于pure function。
A pure function is a function where the return value is only determined by its input values, without observable side effects.
①不改变input ②类似数学中函数y=f(x), x确定,y就唯一确定。
React.PureComponent is exactly like React.Component but implements shouldComponentUpdate() with a shallow prop and state comparison.
——react.purecomponent
如何实现shouldComponentUpdate的呢? 大致是这样的
shouldComponentUpdate
if (this._compositeType === CompositeTypes.PureClass) { shouldUpdate = !shallowEqual(prevProps, nextProps) || ! shallowEqual(inst.state, nextState); }
提高React的速度。 此概念是相对于Component提出的。如何提高了速度呢? mount的时候Component中的shouldComponentUpdate始终返回true。
Component
true
PureComponent
state
props
render
更少的VirtualDOM和更少的diff,提高了React的速度。
下图为React更新的示意图,从左到右,update内容逐渐减少。
class FullName extends Component { render() { const { firstName, lastName } = this.props; return ( <div>{firstName} {lastName} - {new Date}</div> ) } }
context
Why and How to Use PureComponent in React.js
Разбор: как и зачем применять PureComponent в React(看评论)
什么是 Impure Component
How to implement shouldComponentUpdate with this.context? #2517
React PureComponent 源码解析
The text was updated successfully, but these errors were encountered:
No branches or pull requests
1.概念来源
来源于pure function。
①不改变input ②类似数学中函数y=f(x), x确定,y就唯一确定。
2.概念
——react.purecomponent
如何实现
shouldComponentUpdate
的呢?大致是这样的
3.目的
提高React的速度。
此概念是相对于Component提出的。如何提高了速度呢?
mount的时候
Component
中的shouldComponentUpdate
始终返回true
。PureComponent
之后,通过判断state
、props
有没有改变,来决定是否render
,render
,那么VirtualDOM就不会生成,更少的VirtualDOM和更少的diff,提高了React的速度。
下图为React更新的示意图,从左到右,update内容逐渐减少。
4.什么不是PureComponent
遗留问题
context
对PureComponent有什么影响?参考文献
Why and How to Use PureComponent in React.js
Разбор: как и зачем применять PureComponent в React(看评论)
什么是 Impure Component
How to implement shouldComponentUpdate with this.context? #2517
React PureComponent 源码解析
The text was updated successfully, but these errors were encountered: