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

docs(cn): translate content/docs/legacy-context.md into Chinese #370

Merged
merged 2 commits into from
Jan 28, 2020
Merged

docs(cn): translate content/docs/legacy-context.md into Chinese #370

merged 2 commits into from
Jan 28, 2020

Conversation

yes1am
Copy link
Contributor

@yes1am yes1am commented Jan 22, 2020

translate content/docs/legacy-context.md into Chinese

@netlify
Copy link

netlify bot commented Jan 22, 2020

Deploy preview for zh-hans-reactjs ready!

Built with commit dbe7193

https://deploy-preview-370--zh-hans-reactjs.netlify.com

@yes1am yes1am mentioned this pull request Jan 22, 2020
Function components are also able to reference `context` if `contextTypes` is defined as a property of the function. The following code shows a `Button` component written as a function component.
只要 `contextTypes` 被定义为函数的一个属性,函数组件也能够引用 `context`。下面的代码展示了一个函数组件写法的 `Button` 组件。

<br/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<br/>

Copy link
Contributor Author

@yes1am yes1am Jan 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -214,4 +216,4 @@ MediaQuery.childContextTypes = {
};
```

The problem is, if a context value provided by component changes, descendants that use that value won't update if an intermediate parent returns `false` from `shouldComponentUpdate`. This is totally out of control of the components using context, so there's basically no way to reliably update the context. [This blog post](https://medium.com/@mweststrate/how-to-safely-use-react-context-b7e343eff076) has a good explanation of why this is a problem and how you might get around it.
问题是,如果组件提供的一个 context 发生了变化,而中间父组件的 `shouldComponentUpdate` 返回 `false`,那么使用到该值的后代组件不会进行更新。使用了 context 的组件则完全失控,所以基本上没有办法能够可靠的更新 context。[这篇博客文章](https://medium.com/@mweststrate/how-to-safely-use-react-context-b7e343eff076)很好地解释了为什么这是一个问题,以及你该如何规避它。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
问题是,如果组件提供的一个 context 发生了变化,而中间父组件的 `shouldComponentUpdate` 返回 `false`,那么使用到该值的后代组件不会进行更新。使用了 context 的组件则完全失控,所以基本上没有办法能够可靠的更新 context。[这篇博客文章](https://medium.com/@mweststrate/how-to-safely-use-react-context-b7e343eff076)很好地解释了为什么这是一个问题,以及你该如何规避它。
问题是,如果组件提供的一个 context 发生了变化,而中间父组件的 `shouldComponentUpdate` 返回 `false`,那么使用到该值的后代组件不会进行更新。使用了 context 的组件则完全失控,所以基本上没有办法能够可靠的更新 context。[这篇博客文章](https://medium.com/@mweststrate/how-to-safely-use-react-context-b7e343eff076)很好地解释了为何会出现此类问题,以及你该如何规避它。


React has an API to update context, but it is fundamentally broken and you should not use it.
React 有一个 API 可以更新 context,但它基本上是坏的,你不应该使用它。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
React 有一个 API 可以更新 context,但它基本上是坏的,你不应该使用它。
React 有一个 API 可以更新 context,但它基本上是不靠谱的,你不应该使用它。

@QC-L
Copy link
Member

QC-L commented Jan 26, 2020

@yes1am 修改下,大体没啥问题

@QC-L QC-L merged commit e5c998c into reactjs:master Jan 28, 2020
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

Successfully merging this pull request may close these issues.

2 participants