Maaz Zindani

Loading the index…

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

ESLint says an arrow function has an unneeded block body

ErrorUnexpected 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.

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

Fix it fast

  1. 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.jsx
  2. 2Match what you see, then jump to its fix

    1. 1The flagged arrow function looks like () => { return value; }A block body that only returns a valueFix
    2. 2The function returns { ... } and the report still points at the arrowAn object literal returned from a blockFix
    3. 3The code is fine but the rule disagrees with your styleYour team wants braces everywhere, or no rule at allFix

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.jsx

2Fix

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.jsx

Confirmed by eslint.org

Did this fix it?

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/null

2Fix

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.jsx

Confirmed by eslint.org

Did this fix it?

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/null

2Fix

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.jsx

Confirmed by eslint.org

Did this fix it?

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:

Related fixes

Next step

Want this handled for good?

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