2

我在我的应用程序中使用 react-i18nextI18nextProviderwithNamespaces.

export const App = () => (
    <I18nextProvider i18n={i18n}>
      <App />
    </I18nextProvider>
);
export default withNamespaces()(ChildComponentOfApp);

但我不明白I18nextProviderand的关系withNamespaces。他们不传递道具之类的t功能

提供者负责使用 react context api 将 props 传入的 i18next 实例向下传递给所有 withNamespaces hocs 或 NamespacesConsumer 渲染 prop。

是为什么工作?这是渲染道具withNamespaces吗?

我知道那是 HOC,但在阅读 react-i18next 源代码之后甚至混淆withNamespaces了这种关系。I18nextProviderwithNamespaces

有人可以解释一下吗?

4

1 回答 1

3

I18nextProvider -> 你传入一个包含要使用的 i18next 实例的道具“i18n” -> Provider 使用 react 的上下文 API 将其向下传递到 JSX 树

withNamespaces -> 从上下文中获取 i18n 实例并将 at 函数传递给您的组件。

于 2019-03-26T15:37:07.613 回答