Skip to content

docs: clarify iterable render returns - #8606

Open
Rezakarimzadeh98 wants to merge 1 commit into
reactjs:mainfrom
Rezakarimzadeh98:fix/render-iterables-docs
Open

docs: clarify iterable render returns#8606
Rezakarimzadeh98 wants to merge 1 commit into
reactjs:mainfrom
Rezakarimzadeh98:fix/render-iterables-docs

Conversation

@Rezakarimzadeh98

Copy link
Copy Markdown

Summary

Clarify that
ender may return iterables of React nodes, and warn that iterators should be recreated each render.

Why

This avoids confusion around returning iterators from class components in development, where React may call
ender more than once and a reused iterator can already be consumed.

Changes

  • mention iterables as valid render return values
  • warn that each render should create a fresh iterator when returning one

Copilot AI lite review requested due to automatic review settings August 17, 2026 08:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the React class component reference docs to clarify that render may return iterables (not just arrays) of React nodes, and to warn about pitfalls when returning iterators that can be consumed across renders (notably in development).

Changes:

  • Expands the “Returns” description to include iterables of React nodes.
  • Adds a caveat warning about returning iterators from render and the need to create a fresh iterator per render.
Suppressed comments (1)

src/content/reference/react/Component.md:586

  • This new iterator caveat largely repeats the Strict Mode bullet immediately below and implies extra development-only renders in general. Consider reordering so the Strict Mode explanation comes first, and tighten the iterator warning to the core issue (iterators are consumed).
- If you return an iterator from `render`, make sure each render creates a fresh iterator. React may render more than once in development, and a reused iterator may already be consumed. When possible, prefer returning an array or another reusable iterable.

- When [Strict Mode](/reference/react/StrictMode) is on, React will call `render` twice in development and then throw away one of the results. This helps you notice the accidental side effects that need to be moved out of the `render` method.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

#### Returns {/*render-returns*/}

`render` can return any valid React node. This includes React elements such as `<div />`, strings, numbers, [portals](/reference/react-dom/createPortal), empty nodes (`null`, `undefined`, `true`, and `false`), and arrays of React nodes.
`render` can return any valid React node. This includes React elements such as `<div />`, strings, numbers, [portals](/reference/react-dom/createPortal), empty nodes (`null`, `undefined`, `true`, and `false`), arrays of React nodes, and iterables of React nodes.
@github-actions

Copy link
Copy Markdown

Size changes

Details

📦 Next.js Bundle Analysis for react-dev

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants