[英]What is difference between JSX literal and a component? React.jsx: type is invalid -- expected a string
Error: Warning: React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: .错误:Warning: React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got:. Did you accidentally export a JSX literal instead of a component?
您是否不小心导出了 JSX 文字而不是组件? at App
在应用
const withHigherOrderComponent = (Component) => {
console.log(Component);
return <Component />;
};
const BaseTodoList = ({ data = [] }) => {
return (
<ul>
{data.map((item) => (
<div key={Math.random()}>{item}</div>
))}
</ul>
);
};
const TodoList = withHigherOrderComponent(BaseTodoList);
export default TodoList;
your HOC does not return a component ( which should be a function
or Class
), but it calls the passed component and returns the result.您的 HOC 不会返回组件(应该是
function
或Class
),但它会调用传递的组件并返回结果。
It should be它应该是
const withHigherOrderComponent = (Component) => {
console.log(Component);
return () => <Component />;
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.