Uncaught Error: Objects are not valid as a React child (found: object with keys {name, age}). 报错问题

Uncaught Error: Objects are not valid as a React child (found: object with keys {name, age}). 报错问题_第1张图片

这个错误的大概意思就是:对象不是合法的react子对象,如果你想要渲染一个子对象集合,请使用数组代替。

查阅资料后发现:react中是不允许直接在页面中渲染对象{name:"xxx",age:18}的,但是可以渲染数组["xxx",18]和基本数据类型

使用context通信,使得父组件给子组件传递一个对象信息(暂未接触context通信的同学不会在乎,只要知道此时父组件给子组件传递了一个对象)

Uncaught Error: Objects are not valid as a React child (found: object with keys {name, age}). 报错问题_第2张图片Uncaught Error: Objects are not valid as a React child (found: object with keys {name, age}). 报错问题_第3张图片Uncaught Error: Objects are not valid as a React child (found: object with keys {name, age}). 报错问题_第4张图片

直接在页面上渲染一个对象,会爆错

Uncaught Error: Objects are not valid as a React child (found: object with keys {name, age}). 报错问题_第5张图片

Uncaught Error: Objects are not valid as a React child (found: object with keys {name, age}). 报错问题_第6张图片

应该分别渲染,此时不会报错

你可能感兴趣的:(报错问题,react.js,javascript,前端)