【问题标题】:React render on I18nextProvider causing React.createElement type is invalid errors [duplicate]I18nextProvider 上的 React 渲染导致 React.createElement 类型无效错误 [重复]
【发布时间】:2021-09-30 05:22:48
【问题描述】:

我正在像这样导入I18nextProviderimport { I18nextProvider } from "react-i18next"

我是这样使用的:

ReactDOM.render(
    <I18nextProvider i18n={myTranslator.getInstance()}>
        <MyComponent {...props} />
    </I18nextProvider>,
    this.target
);

但是,在 I18nextProvider 组件上,我在尝试渲染时在玩笑测试中遇到错误,但在常规构建或使用中却没有。看看其他情况,似乎我的进口可能是问题,但我的进口似乎很好。有什么我遗漏的吗?

---- 编辑 ---- 看起来这是以下内容的副本:How to fix `TypeError: Cannot read property 'type' of undefined` when testing i18next with Jest。我的笑话配置需要更新的地方。

【问题讨论】:

    标签: reactjs i18next react-i18next


    【解决方案1】:

    您使用的是默认导入,但此处需要命名导入

    import { I18nextProvider } from 'react-i18next';
    

    【讨论】:

    • 抱歉,我的问题中有错字。导入已按照您的建议命名。但它仍然会抛出错误,而且只是开玩笑。
    • 你在你的 jest conf 中添加了这个吗??
    • 在我的情况下,我将它作为全局配置的一部分,我删除了它,因为它只需要 2 个组件。这解决了我这边的问题。
    猜你喜欢
    • 2018-04-28
    • 2019-08-19
    • 2021-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-22
    • 2019-11-03
    • 2018-12-25
    相关资源
    最近更新 更多