简体   繁体   English

JSX 文字和组件有什么区别? React.jsx:类型无效——需要一个字符串

[英]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 不会返回组件(应该是functionClass ),但它会调用传递的组件并返回结果。

It should be它应该是

const withHigherOrderComponent = (Component) => {
  console.log(Component);
  return () => <Component />;
};

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 React.jsx:类型无效——需要一个字符串 - React.jsx: type is invalid -- expected a string React.jsx:类型无效 - 需要一个字符串(对于内置组件) - 尝试将类组件转换为功能组件 - React.jsx: type is invalid -- expected a string (for built-in components) - Try convert class component to functional component react React.jsx:类型无效 - 需要一个字符串(对于内置组件)或一个类/函数(对于复合组件)但得到:未定义 - React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined React.jsx:类型无效——需要一个字符串(对于内置组件)或一个类/函数(对于复合组件)但得到:object - React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object 尝试使用 Reactstrap 卡时,我收到警告:React.jsx:类型无效 - 需要字符串(用于内置组件)或类/函数? - When trying to use Card of Reactstrap I get Warning: React.jsx: type is invalid -- expected a string (for built-in components) or a class/function? Form.File 正在调用错误 React.jsx: type is invalid -- 期望字符串或类/函数(对于复合组件)但得到:未定义 - Form.File is invoking error React.jsx: type is invalid -- expected a string or a class/function (for composite components) but got: undefined 元素类型无效:应为字符串,使用 JSX 定义组件 - Element type is invalid: expected a string, using JSX to define a component REACT.jsx 未在浏览器中显示 - REACT.jsx not showing in Browser JSX 中的 {} 和 ${} 有什么区别? - What is the difference between {} and ${} in JSX? React 中的 .js、.tsx 和 .jsx 有什么区别? - What is the difference between .js, .tsx and .jsx in React?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM