reactjs / reactjs/react.dev

Document we should probably use React.memo under our Context Provider

Open
#2,975 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
11.8k
Forks
7.9k
Avg merge
1d 11h
Merged PRs (30d)
11

Description

It is not immediately obvious that when the component that declares the context provider re-renders, all its descendants will also render, and not just the components that subscribe to the context.

This has been made explicit by @sophiebits on Twitter: https://twitter.com/sophiebits/status/1228942768543686656, and @markerikson on his blog: https://blog.isquaredsoftware.com/2020/05/blogged-answers-a-mostly-complete-guide-to-react-rendering-behavior/#context-updates-and-render-optimizations, but following the right people on twitter should not be a requirement to understand how React is supposed to be used.

While it's true that if one reasons about how React decides to render components (given one has a sufficient understanding of it) this behaviour can be inferred, I still think that an explicit recommendation would help a majority of React users.

Happy to try submitting a PR if needed :)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No specific file or test is named. Locate the React Context Provider guidance in the react.dev documentation and review the linked rendering references; done means the documentation clearly explains descendant re-renders and states the intended React.memo recommendation.

Written by the indexing model from the issue text.

Assessment

Tech stack
react
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.