TypeScript says void is not assignable to ReactNode in a React component
Error: 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.
Fix it fast
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 --noEmit2Match what you see, then jump to its fix
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=*.tsx2Fix
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 --noEmitConfirmed by react.dev
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=*.tsx2Fix
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 --noEmitConfirmed by react.dev
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:
- 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.
- TaskvareA task and project-management suite: React on the web, Flutter on mobile, TypeScript underneath.
Related fixes
Web apps
TypeScript refuses JSX because the jsx option is not set
TS17004: Cannot use JSX unless the '--jsx' flag is provided.
TypeScript compiles JSX only when you name the file with a .tsx extension and enable the jsx compiler option.
2 causes, each with a fixWeb apps
TypeScript rejects a component that returns an array or other non-Element
Its return type 'Element[]' is not a valid JSX element.
TypeScript before 5.1 required every component to return JSX.Element or null, so arrays, strings and Promises were rejected even though React renders them.
2 causes, each with a fixWeb apps
ESLint says it cannot resolve a path to a module that does exist
Unable to resolve path to module 'react'. import/no-unresolved
import/no-unresolved fails when eslint-plugin-import cannot find the file or package on disk with its resolver.
4 causes, each with a fixWeb apps
ESLint reports no-unused-vars for React components and imports that are used
no-unused-vars reported for a component that is rendered as a JSX tag
ESLint's core no-unused-vars does not see variables used only as JSX tags, so a component imported and rendered as <Hello /> looks unused.
3 causes, each with a fixWeb 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 fixWeb apps
The renderInput prop stopped working on the MUI X DatePicker
The custom TextField (variant, size, helperText) is ignored
renderInput was removed from the MUI X date pickers in version 6.
3 causes, each with a fix