【问题标题】:Functions are not valid as a React child. Hello there. I have an error in my code. Please tell me how to fix it函数作为 React 子项无效。你好呀。我的代码有错误。请告诉我如何解决它
【发布时间】:2023-02-16 00:03:47
【问题描述】:
const PersonDetails = () => {
  return (
    <SwapiServiceConsumer>
      {({ getPerson }) => {
        return witdDetails(ItemDetails, getPerson);
      }}
    </SwapiServiceConsumer>
  );
};

export default PersonDetails;
  • 如何在另一个方法中返回 withDetails。
  • 我需要在消费者上调用 withDetails (HOC)。

【问题讨论】:

  • 你得到的错误是什么,是什么引发的?
  • 函数作为 React 子项无效。返回不是一个函数。

标签: reactjs function


【解决方案1】:

函数无效,因为此函数返回一个函数,

功能组件需要返回有效的 JSX 而不是函数

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-24
    • 2012-07-24
    • 1970-01-01
    • 1970-01-01
    • 2014-05-03
    • 1970-01-01
    • 1970-01-01
    • 2021-03-15
    相关资源
    最近更新 更多