ESLint says an element in a list is missing its key prop
Missing "key" prop for element in iterator react/jsx-keyShort answer
react/jsx-key fires when an element returned from map, Array.from or an array literal has no key. Put a stable key on the element directly inside the loop, use Fragment with a key for multi-node items, and write key before any prop spread.
Fix it fast
1Find out which cause you have
Run ESLint on the file. The reported line is the element inside the loop that lacks the key.
npx eslint src/2Match what you see, then jump to its fix
- 1
A .map callback returns JSX with no key attribute.The mapped element has no keyFix - 2
The loop returns <>...</>. Shorthand fragments cannot take a key; the rule flags them when checkFragmentShorthand is enabled.Each item renders several nodes, or a shorthand fragmentFix - 3
A list item is a custom component, and the key sits on its root div; or key arrives through {...props} or comes after the spread.The key is on the wrong element, or only inside a spreadFix
- 1
What does the error look like?
Missing "key" prop for element in iterator react/jsx-keyreact/jsx-key
Cause 1 of 3
The mapped element has no key
1Check
JSX elements directly inside a map call always need keys. The rule also checks Array.from callbacks and array literals.
grep -rn "\.map(" --include="*.tsx" src | head2Fix
Add a stable, unique key from your data, such as a database id. Avoid index keys for lists that can reorder, and never use Math.random().
{users.map((user) => (
<li key={user.id}>{user.name}</li>
))}3Verify
Run ESLint again on the file.
npx eslint src/components/UserList.tsxConfirmed by react.dev
Cause 2 of 3
Each item renders several nodes, or a shorthand fragment
1Check
Find loops that return a shorthand fragment or sibling elements without a wrapper.
grep -rn "=> *<>\|return *<>" --include="*.tsx" src2Fix
Import Fragment and put the key on it. Fragments leave no extra element in the DOM.
import { Fragment } from 'react';
{people.map((p) => (
<Fragment key={p.id}>
<h2>{p.name}</h2>
<p>{p.bio}</p>
</Fragment>
))}3Verify
Run ESLint; the fragment line is clean.
npx eslint src/Confirmed by react.dev
Cause 3 of 3
The key is on the wrong element, or only inside a spread
1Check
The key belongs on the element in the map call, not on the root inside the component. The rule also treats a key that exists only in a spread object as missing, and with checkKeyMustBeforeSpread it flags a key placed after a spread.
grep -rn "{\.\.\." --include="*.tsx" src | head2Fix
Move the key to the component call and write it before the spread. Pass the id again as a normal prop if the component needs it.
{recipes.map((r) => (
<Recipe key={r.id} {...r} />
))}3Verify
Run ESLint again.
npx eslint src/Confirmed by raw.githubusercontent.com
How do I stop it coming back?
- Give every record a stable id when you fetch or create it, and use it as the key.
- Keep react/jsx-key on in your ESLint config so the warning shows in the editor.
- Use a keyed Fragment, not an extra wrapper div, when a list item has several nodes.
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
There is no tailwind.config.js after installing Tailwind 4 and HeroUI in Next.js
HeroUI components render unstyled
Nothing is broken: Tailwind CSS 4 is configured in CSS and no longer creates tailwind.config.js.
3 causes, each with a fixWeb apps
react-i18next shows the wrong plural form for a count, or prints the key instead of the text
t('item') prints the key item instead of a translated sentence
i18next picks a plural from the count option and looks for keys ending in _one, _other and so on.
4 causes, each with a fixWeb apps
useSession throws because there is no SessionProvider above it
[next-auth]: `useSession` must be wrapped in a <SessionProvider />
useSession reads the session from React Context, and SessionProvider is what creates that context.
3 causes, each with a fixWeb apps
next/link throws React.Children.only on its children
Error: React.Children.only expected to receive a single React element child.
React.Children.only accepts exactly one React element and throws for anything else, including an array with one item.
3 causes, each with a fixWeb apps
Hydration failed after adding next-themes dark mode
Console reports a server and client mismatch on the html element
next-themes changes the html element and knows the theme only in the browser, so server HTML and client HTML differ.
3 causes, each with a fixWeb apps
Upgrading to Next.js 16: middleware becomes proxy, and the other things that break
Missing Required default.js for Parallel Route
Next.js 16 renames middleware.ts to proxy.ts and its exported function to proxy.
6 causes, each with a fix