最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

单个React元素子错误

IT培训 admin 10浏览 0评论

单个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>

单个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. 暂无评论