【问题标题】:React + Redux connecting error. Objects are not valid as a React child (found: object with keys {$$typeof, type, compare, WrappedComponent})React + Redux 连接错误。对象作为 React 子对象无效(发现:对象与键 {$$typeof, type, compare, WrappedComponent})
【发布时间】:2021-03-05 20:33:01
【问题描述】:

这是一个发送框https://codesandbox.io/s/busy-euler-7mpi7?file=/src/main.js

如您所见,它给了我错误。我要做的是在 main.js 中连接 Redux 存储。如果您在 main.js 中删除 connect 并保持组件不变,它将正常工作。但是一旦你在 main.js 中使用connect,它就会破坏 React 应用程序。连接时我做错了什么?

【问题讨论】:

    标签: reactjs redux connect


    【解决方案1】:

    问题在于您在 routes.js 中的对象

    {
        url: "/",
        component: Main,
        exact: true
    }
    

    这里,Main 并不代表有利于传递给 Route Element 的组件。 (可能换行后连接的返回结构不同)

    尝试将其更改为

    {
        url: "/",
        component: <Main/>,
        exact: true
    }
    

    它会起作用的。

    【讨论】:

      猜你喜欢
      • 2020-06-28
      • 2021-03-16
      • 2018-11-06
      • 1970-01-01
      • 2021-06-07
      • 2018-11-19
      • 1970-01-01
      • 1970-01-01
      • 2021-08-05
      相关资源
      最近更新 更多