Maaz Zindani

Loading the index…

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

TypeScript says void is not assignable to ReactNode in a React component

ErrorError: Type 'void' is not assignable to type 'ReactNode'

Short answer

The expression inside your JSX returns nothing, so TypeScript sees void where React wants renderable content. The usual cause is an arrow function with a block body, { }, in .map() that has no return. Add return, or drop the braces so the JSX is returned implicitly.

  • Applies to React 19, TypeScript 5
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Open the exact line TypeScript flags and find the function that produces the value between the JSX braces. Ask what it returns.

    npx tsc --noEmit
  2. 2Match what you see, then jump to its fix

    1. 1The error points at {items.map(...)} inside JSXA .map() callback uses { } but has no returnFix
    2. 2A component or render helper has return alone on a line, and the JSX starts on the nextreturn is on its own line, so the markup is ignoredFix

What does the error look like?

  • Error: Type 'void' is not assignable to type 'ReactNode'

Cause 1 of 2

A .map() callback uses { } but has no return

1Check

An arrow function returns the expression after => by itself only without braces. With a curly brace it has a block body, and you must write return. If you forget it, nothing gets returned.

grep -rn "\.map(.*=> {" src --include=*.tsx

2Fix

Add the return, or remove the braces.

// block body with return
{people.map(person => {
  return <li key={person.id}>{person.name}</li>
})}

// or implicit return
{people.map(person => <li key={person.id}>{person.name}</li>)}

3Verify

Run the type check; the error goes away and the list renders.

npx tsc --noEmit

Confirmed by react.dev

Did this fix it?

Cause 2 of 2

return is on its own line, so the markup is ignored

1Check

Without parentheses, any code on the lines after return is ignored, so the function returns undefined.

grep -rn "return$" -A3 src --include=*.tsx

2Fix

Put the markup on the same line as return, or open parentheses right after it.

function Badge() {
  return (
    <span>New</span>
  )
}

3Verify

Run the type check and open the page.

npx tsc --noEmit

Confirmed by react.dev

Did this fix it?

How do I stop it coming back?

  • Prefer the implicit-return form of arrow functions for simple list items.
  • Keep the TypeScript check in CI so the mistake never reaches a build.
  • Always open the parenthesis on the return line.

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

Web apps

TypeScript rejects MUI Data Grid columns that set a type

A TypeScript error inside a column's renderCell callback

A columns array declared without a type is inferred with type as a plain string, which the Data Grid's column type union does not accept.

2 causes, each with a fix

Next step

Want this handled for good?

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