gpt4 book ai didi

javascript - 错误 : name":"Invariant Violation" ,"framesToPop":1

转载 作者:可可西里 更新时间:2023-11-01 10:19:57 34 4
gpt4 key购买 nike

我看到了这个奇怪的错误。我正在编写一个应用程序,它使用图形 api 从 facebook 检索事件详细信息。该事件有几个属性: - 所有者,它是一个包含所有者 ID、所有者名称和其他属性的对象 - cover 代表事件封面图像细节的对象。

我将事件保存在 mongo 数据库中,这是我的事件模型:

const EventSchema = new Schema({
title: String,
name: String,
_id: {
type: String,
unique: true,
default: shortid.generate,
},
start_time: Date,
end_time: Date,
description: String,
owner: {},
cover: {},
venue: {},
privacy: String,
timezone: String,
location: String,
createdAt: { type: Date, default: Date.now },
event_type: {},
});

我有一个通过 id 发回给定事件的快速路由:

router.get('/:id', (req, res) => {
Event.findById(req.params.id).exec((error, events) => {
if (error){
res.json(error);
}
res.json(events);
})
});

我的组件架构是这样的:

-包含 EventDetails 组件的 EventPage 组件。

import React, { PropTypes } from 'react'
import { connect } from 'react-redux'
import axios from 'axios';
import EventDetails from './eventDetails';

class EventPage extends React.Component {
constructor(props) {
super(props);

this.state = {
event: {},
};
}
componentWillMount() {
axios.get(`/api/events/${this.props.params.id}`)
.then((eventResponse) => {
this.setState({
event: eventResponse.data
})
}).catch((err) => {
console.log(JSON.stringify(err));
})
}
render() {
return (
<div className="row">
<EventDetails event={this.state.event} />
</div>
)
}
}

EventPage.propTypes = {
};

export default EventPage;




import React, { PropTypes } from 'react'
import { connect } from 'react-redux'
import _ from 'lodash';

class EventDetails extends React.Component {
constructor(props) {
super(props);
}
render() {
const { name, description, start_time, end_time, owner } = this.props.event;
return(
<div className='row'>
<h1>{name}</h1>
<p>{description}</p>
<p>{JSON.stringify(this.props.event)}</p>
<p>{this.props.event.owner}</p>
<pre>

</pre>


</div>
)
}
}

EventDetails.propTypes = {
};

export default EventDetails;

尝试显示事件所有者的姓名会导致此错误:

{"name":"不变违规","framesToPop":1}

错误来自于 EventPage 组件中的 axios 错误处理程序。

有人看到我在这里做错了什么吗?

谢谢你的帮助

最佳答案

我可能遇到与 {"name":"Invariant Violation","framesToPop":1} 相同的问题。

我传递了一个 javascript 对象而不是数组,它对我有用。

    Message.find({}).sort({'date': -1}).limit(50).exec().then( (doc, err) => {
console.log('found');
const messages = [];
doc.map( (item) => {
messages.push({data: item});
});
callback(err, {items: messages});
});

关于javascript - 错误 : name":"Invariant Violation" ,"framesToPop":1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40251052/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com