ESLint says an arrow function has an unneeded block body
Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`Short answer
This message comes from the arrow-body-style rule. Its default mode, as-needed, wants an arrow function whose block holds only a return to use a short expression body instead. Run eslint --fix, remove the braces and return by hand, or change the rule option to always or off if your team prefers braces.
Fix it fast
1Find out which cause you have
Confirm which rule raised the error and whether ESLint can fix that spot on its own. The rule id is printed at the end of the line.
npx eslint src/App.jsx2Match what you see, then jump to its fix
- 1
The flagged arrow function looks like () => { return value; }A block body that only returns a valueFix - 2
The function returns { ... } and the report still points at the arrowAn object literal returned from a blockFix - 3
The code is fine but the rule disagrees with your styleYour team wants braces everywhere, or no rule at allFix
- 1
What does the error look like?
Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`arrow-body-style
Cause 1 of 3
A block body that only returns a value
1Check
Open the line ESLint reports. If the braces hold nothing but one return statement, this is the case the default as-needed mode rejects.
npx eslint src/App.jsx2Fix
Let ESLint rewrite it, or delete the braces and the return keyword yourself so the value follows the arrow. The rule is documented as partly auto-fixable.
npx eslint src --fix
// by hand
// before: const double = (n) => { return n * 2; };
const double = (n) => n * 2;3Verify
Run ESLint again on the file. The rule id must be gone from the output.
npx eslint src/App.jsxConfirmed by eslint.org
Cause 2 of 3
An object literal returned from a block
1Check
An object literal as an expression body needs parentheses, so the shortened form looks odd to many people. The rule has a second option for exactly this.
grep -rn "arrow-body-style" eslint.config.js .eslintrc* package.json 2>/dev/null2Fix
Either write the object in parentheses after the arrow, or set requireReturnForObjectLiteral to true so such functions keep a block with an explicit return. That option only applies with as-needed.
// parentheses form
const toUser = (name) => ({ name });
// eslint.config.js
export default [
{
rules: {
"arrow-body-style": ["error", "as-needed", { requireReturnForObjectLiteral: true }],
},
},
];3Verify
Lint the file and check that the object-returning function is accepted.
npx eslint src/App.jsxConfirmed by eslint.org
Cause 3 of 3
Your team wants braces everywhere, or no rule at all
1Check
The rule has three modes: as-needed (the default), always and never. A shared config may set one of them, so look for where it comes from.
grep -rn arrow-body-style eslint.config.* .eslintrc* package.json 2>/dev/null2Fix
Change the first option to always to require braces, or turn the rule off. A rule set to off, or 0, is disabled.
// eslint.config.js
export default [
{
rules: {
"arrow-body-style": "off",
},
},
];3Verify
Run ESLint on the file again; no arrow-body-style report should remain.
npx eslint src/App.jsxConfirmed by eslint.org
How do I stop it coming back?
- Run eslint --fix in a pre-commit hook so the short form is written for you.
- Pick one mode for the whole team and keep it in the shared config, not per file.
- If you return objects often, set requireReturnForObjectLiteral once instead of arguing in reviews.
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 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 fixWeb apps
An axios call never finishes when the API server stops answering
code: 'ECONNABORTED'
Axios has no timeout unless you give it one: the default is 0, which means wait forever.
3 causes, each with a fix