Skip to content

Clarify why fetching stays in the Effect in "Fetching data" - #8564

Open
deepusnath wants to merge 1 commit into
reactjs:mainfrom
deepusnath:docs/clarify-fetching-data-effect
Open

Clarify why fetching stays in the Effect in "Fetching data"#8564
deepusnath wants to merge 1 commit into
reactjs:mainfrom
deepusnath:docs/clarify-fetching-data-effect

Conversation

@deepusnath

@deepusnath deepusnath commented Jul 30, 2026

Copy link
Copy Markdown

The "Fetching data" example keeps page in the Effect's dependency array while also updating it from handleNextPageClick, which reads as a contradiction with the page's own advice to prefer event handlers.

Add a paragraph making the deciding factor explicit: fetch in the handler when a value can only change from that event, and synchronize in an Effect when the value can also change for other reasons (here, page and query can both come from the URL via Back/Forward).

Addresses #8506

@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! 🙌

The "Fetching data" example keeps `page` in the Effect's dependency
array while also updating it from `handleNextPageClick`, which reads as
a contradiction with the page's own advice to prefer event handlers.

Add a paragraph making the deciding factor explicit: fetch in the
handler when a value can *only* change from that event, and synchronize
in an Effect when the value can also change for other reasons (here,
`page` and `query` can both come from the URL via Back/Forward).

Addresses reactjs#8506

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@deepusnath
deepusnath force-pushed the docs/clarify-fetching-data-effect branch from c8760b6 to 99976e5 Compare July 30, 2026 18:10
@deepusnath
deepusnath marked this pull request as draft July 30, 2026 18:11
@deepusnath
deepusnath marked this pull request as ready for review July 30, 2026 18:33
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.

1 participant