简体   繁体   English

在道具分配中使用扩展运算符时,React Native接收错误:“在此环境中,assign的目标必须是对象

[英]React Native receive error when spread operator is used in props assignment: "In this environment the target of assign must be an object

I'm currently using React with Redux and when I run the following: 我目前正在使用React与Redux,当我运行以下内容时:

const mapStateToProps = state => {
  const employees = _.map(state.employees, (val, uid) => {
    return { ...val, uid };
  });

I get the error stated above which seems to be targeting "...val" in the return method. 我得到上面所述的错误,似乎是在返回方法中以“... val”为目标。 I'm basically trying to pull all the information I had from Firebase and returning it in the variable "employees." 我基本上试图从Firebase获取所有信息并将其返回到变量“employees”中。 Any help would be appreciated, thanks! 任何帮助将不胜感激,谢谢!

I think the issue is the typeof val isn't an object (either an array[] or an object {}). 我认为问题是typeof val不是一个对象(array []或object {})。 You can just use return {val, uid} 你可以使用return {val, uid}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 typescript 传播运算符用于反应中的道具抛出错误 - typescript spread operator for props in react throw error 对象分配和传播运算符会改变 React 状态吗? - Object assign and spread operator mutate React state? React Native:当在子组件上使用spread运算符时,将样式作为props传递的正确方法是什么 - React Native: what is a proper way to pass style as props, when using spread operator on the child component 扩展运算符等效于对象分配 - Spread operator equivalent of Object assign React Native AsyncStorage模块导致传播运算符... require('React')出错 - React Native AsyncStorage module causes error with spread operator …require('React') 在 React 中通过扩展运算符传递道具 - Passing props via spread operator in React React 传播运算符 (...props) 没有按预期工作? - React spread operator (...props) not working as expected? React Native中的Spread运算符会导致mocha出现“Unexpected token”错误 - Spread operator in React Native causes 'Unexpected token' error with mocha React 组件不会接收传递给它的 props。 使用逻辑运算符呈现时 - React component will not receive props passed to it. When rendered with a logical operator 为什么不允许扩散运算符在React Native组件属性赋值中进行性能优化? - Why is not allowing spread operator in React Native component property assignment a performance optimization?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM