简体   繁体   English

警告:Array.prototype.reduce() 期望箭头 function 的返回值

[英]Warning: Array.prototype.reduce() expects a return value from arrow function

const singleParams = [...appliedFilters].reduce((prev, curr) => {
    if (curr.key !== "multi")
        return { ...prev, ...curr.selectedValue.params };
    return;
}, {});

The following function is giving me the following warning in my console.以下 function 在我的控制台中给了我以下警告。

Line 22:13: Array.prototype.reduce() expects a return value from arrow function array-callback-return第 22:13 行:Array.prototype.reduce() 期望箭头 function 数组回调返回的返回值

I can't ignore it since I won't be able to deploy with warnings.我不能忽略它,因为我将无法部署警告。 How do I fix it?我如何解决它?

You need to return prev in else block您需要在 else 块中返回prev

  const singleParams = [...appliedFilters].reduce((prev, curr) => {
        if (curr.key !== "multi")
            return { ...prev, ...curr.selectedValue.params };
        return prev;
    }, {});

暂无
暂无

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

相关问题 array.prototype.reduce:在箭头函数中将字符串值推送到空数组 - array.prototype.reduce: Pushing string value to empty array within arrow function 如何解决这个警告警告 Array.prototype.map() 期望从箭头函数数组回调返回的返回值? - How fix this warrning warning Array.prototype.map() expects a return value from arrow function array-callback-return? Array.prototype.map() 期望来自箭头的返回值 function array-callback-return - Array.prototype.map() expects a return value from arrow function array-callback-return Array.prototype.map() 期望箭头函数的返回值 - Apollo 客户端 -Reactjs - Array.prototype.map() expects a return value from arrow function - Apollo client -Reactjs Array.prototype.reduce() 在 JavaScript 中返回 output 错误 - Array.prototype.reduce() return output wrong in JavaScript Array.prototype.filter() 期望在箭头函数 array-callback-return 结束时返回一个值 - Array.prototype.filter() expects a value to be returned at the end of arrow function array-callback-return 包含初始值后的Array.prototype.reduce()错误 - Array.prototype.reduce() Error After Including Initial Value 递归函数中的Array.prototype.reduce产生意外结果 - Array.prototype.reduce in recursive function is producing unexpected results 我返回 `boolean` 但 Array.prototype.filter() 期望在箭头 function 的末尾返回一个值 - i return `boolean` but Array.prototype.filter() expects a value to be returned at the end of arrow function Array.prototype.map() 期望在箭头函数结束时返回一个值 - Array.prototype.map() expects a value to be returned at the end of arrow function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM