Uncaught Error: Objects are not valid as a React child (found: Error: Objects are not valid as a Rea

Uncaught Error: Objects are not valid as a React child (found: Error: Objects are not valid as a React child (found: object with keys {name}). If you meant to render a collection of children, use an array instead.

class Index extends Component {
    constructor(props) {
        super(props);
    }
    componentDidMount() {}
    
    render() {
      const tagsAry=[{name:1}]

       return (
           
{tagsAry}
) }

意思是:未捕获错误:对象作为React子对象无效(找到:具有键{content,key,duration}的对象)。如果要呈现子对象集合,请改用数组。

该问题原因

  • 主要是在render函数里直接渲染一个对象造成的。

解决方案

  • 换成 非对象类型 数据;
  • 直接渲染数据,类似 tagsAry[0].name 或 对象的属性值;

Notion – The all-in-one workspace for your notes, tasks, wikis, and databases.icon-default.png?t=M4ADhttps://serious-lose.notion.site/React-Error-f41e17be772f4f1ea2b1e6c22a723afe

你可能感兴趣的:(React,react.js,javascript,前端)