最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

单个React元素子错误

运维笔记admin20浏览0评论

单个React元素子错误

单个React元素子错误

当我在尝试学习react / node的代码时,总有新手对我如此裸露。

我在下面看到该组第二个setState的错误。

Invariant Violation:React.Children。仅预期接收单个React元素的孩子

通过阅读,看来我需要将这些语句包装在根组件和/或类似的东西内;有人帮忙吗?

async componentDidMount() {
if (!this.props.isAuthenticated) {
  return;
}

try {


  const notes = await this.notes();
  this.setState({ notes });

  const group = await this.group();
  this.setState({ group });

} catch (e) {

  alert(e);
}

总新手不知所措,因为我正在玩尝试学习react / node的代码。....不变违反:React.Children ....

回答如下:

您需要返回null<></>或某种React组件,例如<div>Foo</div>

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论