ESLint array-callback-return: expected to return a value in an arrow function
Expected to return a value at the end of arrow functionShort 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.
Fix it fast
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'2Match what you see, then jump to its fix
- 1
The callback has an if that returns, and nothing after itA branch ends without a returnFix - 2
The reduce body assigns to the accumulator but has no returnA reduce callback does not return the accumulatorFix - 3
The callback calls a function or sets state and does not use the array that map returnsmap is used only for side effectsFix
- 1
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.jsx2Fix
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.jsxConfirmed by eslint.org
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.jsx2Fix
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.jsxConfirmed by eslint.org
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.jsx2Fix
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.jsxConfirmed by developer.mozilla.org
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:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.
Related fixes
Web apps
React warns that each child in a list should have a unique key prop
Warning: Each child in a list should have a unique "key" prop.
React wants a stable key on the element that sits directly inside a map() call, so it can match list items between renders.
4 causes, each with a fixWeb apps
React shows Attempted import error when importing a component or function
Attempted import error:
The build found the file but not the name you asked for.
2 causes, each with a fixWeb apps
AxiosError Network Error with code ERR_NETWORK in a React app
Network Error
ERR_NETWORK means the request produced no readable response.
4 causes, each with a fixWeb apps
Axios get works with a URL string but ignores the object passed as the second argument
The server log shows a GET with no query string
axios.get takes a URL and an optional config object.
3 causes, each with a fixWeb apps
Can't resolve '../axios' in a React project
Module not found: Error: Can't resolve '../axios'
A path that starts with ./ or ../ is a file path, not the axios package.
3 causes, each with a fixWeb apps
Axios returns 401 from a React app but the login works elsewhere
Error: Request failed with status code 401
A 401 means the server received the request without valid credentials.
3 causes, each with a fix