我是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;
我怎么解决这个问题?什么是最佳做法?
问题出在这里
原文链接:https://www.f2er.com/react/301048.html<div>{this.props.dataMeeting}</div>
您无法在React中渲染对象,也许您正在尝试这样做
<div>{this.props.dataMeeting.title}</div>