Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

ESLint array-callback-return: expected to return a value in an arrow function

ErrorExpected to return a value at the end of arrow function

Short answer

The array-callback-return rule requires callbacks of methods such as map, filter, find and reduce to return a value on every path. The warning appears when a callback has braces but no return, an if with no final return, or a reduce that forgets to return the accumulator. Add the return, or use forEach when you only want side effects.

  • Applies to ESLint 9, React 19, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Run ESLint on the file and read which callback and which line it names; then look at its body for a path that ends without return.

    npx eslint path/to/File.jsx --rule 'array-callback-return: error'
  2. 2Match what you see, then jump to its fix

    1. 1The callback has an if that returns, and nothing after itA branch ends without a returnFix
    2. 2The reduce body assigns to the accumulator but has no returnA reduce callback does not return the accumulatorFix
    3. 3The callback calls a function or sets state and does not use the array that map returnsmap is used only for side effectsFix

What does the error look like?

  • Expected to return a value at the end of arrow function

Cause 1 of 3

A branch ends without a return

1Check

The rule page shows an Array.from callback that returns true inside an if and nothing otherwise; adding return false at the end fixes it. The same applies to map and filter.

grep -n "=> {" path/to/File.jsx

2Fix

Return a value on every path. For a filter, return the boolean; for a map, return the element or null.

const visible = items.filter((item) => {
  if (item.active) {
    return true;
  }
  return false;
});

3Verify

ESLint no longer reports that line.

npx eslint path/to/File.jsx

Confirmed by eslint.org

Did this fix it?

Cause 2 of 3

A reduce callback does not return the accumulator

1Check

The rule page lists a reduce callback that sets memo[item] and never returns memo as incorrect code.

grep -n "reduce(" path/to/File.jsx

2Fix

Return the accumulator at the end of every call.

const byId = list.reduce((memo, item) => {
  memo[item.id] = item;
  return memo;
}, {});

3Verify

ESLint passes and byId has the keys you expect.

npx eslint path/to/File.jsx

Confirmed by eslint.org

Did this fix it?

Cause 3 of 3

map is used only for side effects

1Check

The rule checks callbacks of map, filter, find, reduce, some, every and similar methods. MDN calls a map whose returned array is unused an anti-pattern and recommends forEach or a for...of loop.

grep -n "\.map(" path/to/File.jsx

2Fix

Use forEach when no new array is needed. Keep map for building one, as in JSX lists.

ids.forEach((id) => {
  register(id);
});

3Verify

ESLint passes with no return statement needed.

npx eslint path/to/File.jsx

Confirmed by developer.mozilla.org

Did this fix it?

How do I stop it coming back?

  • Use the one-line arrow form without braces for simple maps, so the value is returned by design.
  • Use map only when you use the array it returns.
  • Keep the rule on in CI so a missing return is found in review, not in production.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.