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

context和生命周期探寻 #8

Open
maiff opened this issue Jun 28, 2017 · 0 comments
Open

context和生命周期探寻 #8

maiff opened this issue Jun 28, 2017 · 0 comments
Labels

Comments

@maiff
Copy link
Owner

maiff commented Jun 28, 2017

context和生命周期探寻

标签(空格分隔): 未分类


组件的子组件以this.props.children形式传进去默认是不会update。
这个很好理解:
显示申明
this.props.children
但是如果组件上是有context无论是否改变也会更新子组件(this.props.children形式)

context用法

官网链接
tip: 子组件一定要写像这样的,不然收到的会是空的对象

P.contextTypes = {
  color: PropTypes.string
}

这里重点说一个bug,当我们用react-intel和mobx的时候,由于各种各样的原因无法改变了context无法更新,所以我们很好奇。是不是context被block掉。

看这篇文章
要点:

  • context确实会被block
  • 不要去改context
  • 为什么提倡immutable数据
  • 的确被block掉了不是没有更新例子
    17.6.29:
  • 可以给IntlProvider加key解决问题

I'd recommend going with <IntlProvider key={locale}> to force a full teardown until the underlying React context issue is resolved.
react-intl issue 234
todo react context should

@maiff maiff added the blog label Jun 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant