当我使用intl库从父组件更改语言对象时,我需要将intl={this.props.intl}传递给子组件进行更新。我正在使用FormattedMessage id="example"或this.props.intl.formatMessage({ id: "example" })。我有一个由父组件和子组件组成的链。所以我需要多次将intl作为props传递给每个子组件或某些组件。如果我需要更新子组件,那么我需要在每个子组件中传递intl。我需要一个解决方案。我不想在每个子组件中都传递this.props.intl。
发布于 2019-01-17 15:11:40
发布于 2019-01-17 15:25:53
考虑使用Context API,当您想要共享组件树的公共内容时,您可以使用这个。
另外,请查看https://hackernoon.com/how-do-i-use-react-context-3eeb879169a2
https://stackoverflow.com/questions/54230408
复制相似问题