在这种情况下,我正在按照我的意愿对对象及其工作进行求和,问题是以下消息:
Expected to return a value in arrow function array-callback-return
这是代码:
data.map((current,index, array) => {
const prevVisitors = array[index - 1 ] ? array[index - 1].visitors : 0
current.visitors += prevVisitors
})
如果没有什么可返回的,我应该使用什么作为返回语句(因为它只是对 Prop 的修改)?在什么情况下这个错误是有用的?
最佳答案
你的代码应该是
data.map((current,index, array) => {
const prevVisitors = array[index - 1 ] ? array[index - 1].visitors : 0
return current.visitors += prevVisitors
})
关于javascript - ReactJS - 数组回调返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50101078/