reactjs – React – 通过道具传递对象
发布时间:2020-12-15 20:49:22 所属栏目:百科 来源:网络整理
导读:我是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 t
我是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> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |