react报错 Objects are not valid as a React child ,If you meant to render a collection of children, use an array instead
产生原因
原生组件JSX语法返回的react虚拟dom中 typeof:Symbol(react.memo) 。react顺利挂载需要typeof:Symbol(react.element))
解决方法
React.createElement() 将memo类型的dom转换为element的dom顺利挂载
--------------------
有人说我举例子不清楚 m_m 我的意思就是,哪个地方报错了,你用React.createElement() 把他包起来就OK了。
举例
//原代码
//1.testDOM.js
render(){
return(<div>JSX</div>)
}
//2.a.js
import testDOM from ./testDOM
component: ()=><testDOM />,//这里传递此组件到高阶组件中使用
//3.b.js
import a from ./a
render(){
let component = a.component
return(<component/>)
}
//会报错:
//Objects are not valid as a React child
//(found: object with keys {$$typeof, type, compare, WrappedComponent, displayName}).
// If you meant to render a collection of children, use an array instead.
//解决方案:
//2.a.js
import testDOM from ./testDOM
import React from 'react'
component: ()=>React.createElement(testDOM),//这里传递此组件到高阶组件中使用