Home > front end >  Warning: Array.prototype.reduce() expects a return value from arrow function
Warning: Array.prototype.reduce() expects a return value from arrow function

Time:12-23

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.

Line 22:13: Array.prototype.reduce() expects a return value from arrow function array-callback-return

I can't ignore it since I won't be able to deploy with warnings. How do I fix it?

CodePudding user response:

You need to return prev in else block

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