Skip to content
New issue

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

使用注意点 #11

Open
ZWkang opened this issue Sep 26, 2018 · 0 comments
Open

使用注意点 #11

ZWkang opened this issue Sep 26, 2018 · 0 comments

Comments

@ZWkang
Copy link
Owner

ZWkang commented Sep 26, 2018

  1. 了解使用pureComponent
    当父级节点更细的时候,子节点也会对应更新渲染,即使此时的state不需要进行render
    pureComponent 帮我们对state props 做一层浅比较。减少不必要的render操作
  2. 一些引用值上的危机
    <TestComponent values={this.props.values || []}/> 如果此时this.props.values 是不存在的话
    则每次都会重新生成一个空数组
  const  defaultArray = [];
  <TestComponent values={this.props.values || defaultArray }/>
  1. 函数方法的绑定
    <TestComponent onChange = { this.handleChange.bind(this)} />
    每一次onchange的时候都会生成一个新的函数
    引用不一致 导致父组件render 同时导致子组件也进行render
    提前绑定 直接传递
    @autoBind
    handleChange(){}
    <TestComponent onChange = { this.handleChange} />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant