How to Fix the React.Children.only Error in React
The error "React.Children.only expected to receive a single React element child." in React means that a component using Children.only received children that are not exactly one React element. It is most likely to happen in components like tooltips or popovers that add mouse events to the child element you pass in. If you make the content inside the component a single element, the error goes away.
In my test environment, I reproduced five patterns that trigger this error. I copied the messages from the console word for word, confirmed that the error disappears after each fix, and checked that the component works.
My test environment was Ubuntu 24.04 and Node.js 22.23.5. I used a project created with the react-ts template of npm create vite@latest (react / react-dom 19.3.1, Vite 8.3.8, TypeScript 7.0.2). As in the template, the components are wrapped in StrictMode. I opened the page with Chromium 158 controlled by Playwright 1.63.0. For the DevTools screenshots, I ran a non-headless Chromium (one that displays a window) on a virtual display (Xvfb). I did not test Next.js or other frameworks, browsers other than Chromium, or how UI library components behave.
- 1. The full error and what happens on the page
- 2. The error happens when children is not exactly one element
- 3. How to fix each cause
- 4. Wrapping in a Fragment removes the error, but the component does not work
- 5. Typing children as ReactElement catches these errors before you open the page
- 6. The same message appears in production builds
The full error and what happens on the page
For the test, I created a Tooltip component that shows a bubble when the mouse hovers over its child element. It takes one child with Children.only and adds mouse events with cloneElement.
import { Children, cloneElement, useState, type ReactElement } from 'react'
type ChildProps = {
onMouseEnter?: () => void
onMouseLeave?: () => void
}
type Props = {
label: string
children: ReactElement<ChildProps>
}
// When the mouse hovers over the child element, show label in a bubble
export function Tooltip({ label, children }: Props) {
const [open, setOpen] = useState(false)
const child = Children.only(children)
return (
<span className="tooltip-wrap">
{cloneElement(child, {
onMouseEnter: () => setOpen(true),
onMouseLeave: () => setOpen(false),
})}
{open && <span role="tooltip">{label}</span>}
</span>
)
}
I placed a paw-print emoji and a button side by side inside this Tooltip.
// Wrong: two elements are placed side by side inside Tooltip
export default function TwoChildren() {
return (
<Tooltip label="ミケをなでます">
<span>🐾</span>
<button type="button">なでる</button>
</Tooltip>
)
}
When I opened the page with the dev server (the same vite as npm run dev), the page stayed blank, and the console showed one red line and one yellow line.
Uncaught Error: React.Children.only expected to receive a single React element child.
at Tooltip (Tooltip.tsx:16:26)
An error occurred in the <Tooltip> component.
Consider adding an error boundary to your tree to customize error handling behavior.
Visit https://react.dev/link/error-boundaries to learn more about error boundaries.
The first line is the error this article is about. It means "React.Children.only expects to receive exactly one React element as children, but it did not." The at Tooltip line shows the file and line where Children.only was called. The second line says that an error happened in the <Tooltip> component, and that you can add an error boundary to control what is shown when an error occurs.

The page stays blank because, when there is no error boundary to catch an error thrown during rendering, React removes the UI from the screen. The official reference on error boundaries describes this behavior.
The error happens when children is not exactly one element
The official reference for Children.only says that if children is a single element, it returns that element, and otherwise it throws an error. In the react 19.3.1 code, the function checks whether the value is a React element with isValidElement, and if not, throws this error.
So I printed what children actually received in each of the patterns that caused the error.
| How it is written inside the component | Value received as children | Children.only |
|---|---|---|
| Two elements side by side | An array of two elements | Error |
| Text only | The string "なでる" |
Error |
| A space and a comment after a closing tag | An array of an element and " " |
Error |
{condition && <button>} where the condition is false |
false |
Error |
Result of map (one item) |
An array of one element | Error |
Wrapped in <>…</> (Fragment) |
One Fragment element | Passes |
| Exactly one element | One element | Passes |
The result of map causes an error even with one item, because it is still an array. The official reference also notes that Children.only throws an error for an array with one element.
How to fix each cause
I fixed each of the five patterns. After each fix, the console showed zero errors and zero warnings. In the cases with a button, hovering over the button showed the bubble with the Japanese label, which means "I'll pet Mike".
Two elements side by side
This is the first example. I put the emoji inside the <button>, so the child of Tooltip becomes one button.
// Fixed: put it inside button so the child is one element
export default function TwoChildrenFixed() {
return (
<Tooltip label="ミケをなでます">
<button type="button">
<span>🐾</span>なでる
</button>
</Tooltip>
)
}
If you want both the emoji and the button to have mouse events, wrap the two in a <span>. (I tested this in the Fragment section below.)

Children is text only
Writing text alone, like <Tooltip label="ミケをなでます">なでる</Tooltip>, also causes the error. This is because the children is a string, not an element. Wrap the text in an element such as a <button>.
// Fixed: wrap the text in an element
<Tooltip label="ミケをなでます">
<button type="button">なでる</button>
</Tooltip>
A space and a comment after a closing tag
Even if it looks like there is only one element, if you write {…} (such as a comment) on the same line after a closing tag, separated by a space, that space is counted as a text child. In the following example, the space before the comment was added to children.
// Wrong: a space and a comment after the closing tag
<Tooltip label="ミケをなでます">
<button type="button">なでる</button> {/* add an icon later */}
</Tooltip>
When I moved the comment to the next line, children became exactly one <button> element and the error went away. Whitespace that includes a line break was not added to children.
// Fixed: move the comment to the next line and remove the space
<Tooltip label="ミケをなでます">
<button type="button">なでる</button>
{/* add an icon later */}
</Tooltip>
The child becomes false when a condition is false
If you write a condition inside Tooltip, such as showing a button only when the user is logged in, children becomes false when the condition is false, and that causes the error. The error does not appear when the condition is true, so this pattern is easy to overlook.
// Wrong: when the condition is false, the child becomes false
export default function Conditional({ canPet = false }: { canPet?: boolean }) {
return (
<Tooltip label="ミケをなでます">
{canPet && <button type="button">なでる</button>}
</Tooltip>
)
}
Move the condition outside Tooltip so that the whole Tooltip is shown or hidden.
// Fixed: move the condition outside Tooltip
export default function ConditionalFixed({ canPet = false }: { canPet?: boolean }) {
return (
canPet && (
<Tooltip label="ミケをなでます">
<button type="button">なでる</button>
</Tooltip>
)
)
}
When canPet was false, nothing was displayed and no error appeared. When it was true, the button and the bubble appeared.
Passing the result of map directly
If you create a list with map and pass it to Tooltip, the array is received even when there is only one item, and that causes the error.
const cats = [{ id: 1, name: 'ミケ' }]
// Wrong: the result of map (an array) is passed as the child
<Tooltip label="猫をなでます">
{cats.map((cat) => (
<button key={cat.id} type="button">
{cat.name}をなでる
</button>
))}
</Tooltip>
Inside map, wrap each item in its own Tooltip. Put the key on the outermost Tooltip that map returns.
// Fixed: wrap each cat in its own Tooltip
export default function MapOneFixed() {
return cats.map((cat) => (
<Tooltip key={cat.id} label={`${cat.name}をなでます`}>
<button type="button">{cat.name}をなでる</button>
</Tooltip>
))
}
Wrapping in a Fragment removes the error, but the component does not work
When there are two elements, wrapping them in <>…</> (a Fragment) makes Children.only pass, because a Fragment is also one React element. However, in my test environment the component did not work.
// Wrong: wrapped in a Fragment to make the child look like one element
<Tooltip label="ミケをなでます">
<>
<span>🐾</span>
<button type="button">なでる</button>
</>
</Tooltip>
With this pattern, the console showed no errors or warnings. However, hovering over the button did not show the bubble. cloneElement adds the mouse event handlers to the Fragment's props. But as the official reference for Fragment explains, a Fragment only groups its contents and does not create a wrapping element. The page also had no element corresponding to the Fragment. The list of props on the same page does not include any event handlers either.
Wrapping the two in a <span> worked. The <span> received the events, and the bubble appeared when the mouse hovered over the button.
// Fixed: wrap in a span instead of a Fragment
<Tooltip label="ミケをなでます">
<span>
<span>🐾</span>
<button type="button">なでる</button>
</span>
</Tooltip>
Typing children as ReactElement catches these errors before you open the page
If you type the children of Tooltip as ReactElement<ChildProps>, the type check (tsc -b, which runs first in the template's npm run build) caught all five mistakes.
src/cases/Conditional.tsx(7,7): error TS2322: Type 'false | Element' is not assignable to type 'ReactElement<ChildProps, string | JSXElementConstructor<any>>'.
src/cases/MapOne.tsx(9,7): error TS2739: Type 'Element[]' is missing the following properties from type 'ReactElement<ChildProps, string | JSXElementConstructor<any>>': type, props, key
src/cases/SpaceChild.tsx(6,6): error TS2746: This JSX tag's 'children' prop expects a single child of type 'ReactElement<ChildProps, string | JSXElementConstructor<any>>', but multiple children were provided.
src/cases/TextChild.tsx(5,35): error TS2747: 'Tooltip' components don't accept text as child elements. Text in JSX has the type 'string', but the expected type of 'children' is 'ReactElement<ChildProps, string | JSXElementConstructor<any>>'.
src/cases/TwoChildren.tsx(6,6): error TS2746: This JSX tag's 'children' prop expects a single child of type 'ReactElement<ChildProps, string | JSXElementConstructor<any>>', but multiple children were provided.
The output above omits the second line of TS2322 (the detailed reason). The pattern with only a space left over was also caught, as TS2746 (multiple children). The pattern wrapped in a Fragment passed the type check.
As the Vite documentation explains, the Vite dev server does not perform type checking, so the page opens even when there are type errors. When you first notice this error, running tsc -b shows which file and line the problem is in, and what was passed.
The same message appears in production builds
In a production build (the page opened with vite preview after vite build), the pattern with two elements side by side showed the same "React.Children.only expected to receive a single React element child." error, and the page stayed blank. Unlike in development, the yellow informational line did not appear. Because the error message is the same, you can use the causes above to track it down when you find it in production.
The official reference also warns that both Children and cloneElement are rarely needed APIs and that code using them tends to be fragile. As alternatives, the Children page covers patterns such as render props, and the cloneElement page covers render props and Context. If you are building your own component, these are candidates to consider.




