我想将我的 react 组件的状态设置为一组对象。这是我当前的代码:
componentDidMount() {
axios.get('http://localhost:4000/')
.then(res => {
const newJobs = res.data.map(job => job);
console.log(newJobs)
this.setState({
jobs: newJobs
})
})
.catch(err => console.log(err));
}
res.data 包含一个对象数组,然后我将其映射到一个新列表 newJobs。我将此记录到控制台,它似乎提供了我想要的东西,一组对象:[{...},{...},{...}]。然后我尝试将工作状态设置为 newJobs 数组,但它给了我一个错误:
<块引用>错误:对象作为 React 子对象无效(找到:带有键 {skills, _id, title, description, otherSkills, price, __v} 的对象)。如果您打算渲染一组子项,请改用数组。
这里有什么问题?