reactjs – React – 通过道具传递对象

前端之家收集整理的这篇文章主要介绍了reactjs – React – 通过道具传递对象前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我是React的新手并尝试通过属性传递对象但是会出现以下错误.
Uncaught Invariant Violation: Objects are not valid as a React child (found: object with keys {title}). If you meant to render a collection of children,use an array instead or wrap the object using createFragment(object) from the React add-ons. Check the render method of MeetingComponent.

这是我的代码

Main.jsx

import React from 'react';
import MeetingComponent from '../components/Meeting.jsx';

let meeting = {
  title: 'Some title'
};

class AppComponent extends React.Component {
    render() {
        return (
            <div className="index">
                <MeetingComponent dataMeeting={meeting} />
            </div>
    );
  }
}

AppComponent.defaultProps = {};

export default AppComponent;

Meeting.jsx

import React from 'react';

class MeetingComponent extends React.Component {
    render() {
        return (
            <div>{this.props.dataMeeting}</div>
        );
    }
}

MeetingComponent.defaultProps = {};

export default MeetingComponent;

我怎么解决这个问题?什么是最佳做法?

问题出在这里
<div>{this.props.dataMeeting}</div>

您无法在React中渲染对象,也许您正在尝试这样做

<div>{this.props.dataMeeting.title}</div>
原文链接:https://www.f2er.com/react/301048.html

猜你在找的React相关文章