我是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.jb51.cc/react/301048.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。