【问题标题】:index.js:1 Warning: A context consumer was rendered with multiple childrenindex.js:1 警告:上下文消费者使用多个孩子呈现
【发布时间】:2021-02-26 03:13:01
【问题描述】:

我只是尝试使用 react 提供程序,但不知何故我得到了这个错误:index.js:1437 警告:一个上下文消费者被渲染了多个孩子,或者一个不是函数的孩子。上下文使用者需要一个作为函数的子节点。如果你确实传递了一个函数,请确保

index.js:1 警告:上下文使用者使用多个子级或不是函数的子级呈现。上下文使用者需要一个作为函数的子节点。如果您确实传递了一个函数,请确保它周围没有尾随或前导空格。

function MiveJat() {
  const consumer = React.useContext(abAnarContext);
  console.log(consumer);
  return (
    <abAnarContext.Consumer>
      <div>GOlabi</div>
    </abAnarContext.Consumer>
  );
}

【问题讨论】:

    标签: reactjs react-context


    【解决方案1】:

    只需删除您的组件

    function MiveJat() {
      const consumer = React.useContext(abAnarContext);
      console.log(consumer);
      return (
          <div>GOlabi</div>
      );
    }
    

    然后它会再次工作

    【讨论】:

      猜你喜欢
      • 2021-12-25
      • 1970-01-01
      • 2022-12-23
      • 2022-08-08
      • 1970-01-01
      • 2022-12-20
      • 1970-01-01
      • 2021-07-20
      • 2018-11-14
      相关资源
      最近更新 更多