Skip to content

Added a note about use in useContext page to make developers more aware of it. #7728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

karthik-awebon
Copy link
Contributor

@karthik-awebon karthik-awebon commented Apr 8, 2025

As per the suggestion explained in #7723 I had added a note in useContext page for the use(context) hook.
@rickhanlonii can you please review this PR.
Thanks

Fixes #7723


[`use(context)`](/reference/react/use) is preferred over `useContext` when you need to access context inside conditionals (like if) or loops (like for), as it is more flexible than `useContext`.

</Note>
Copy link
Member

Choose a reason for hiding this comment

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

Let's move this to the top, after <Intro> and have it say:

Starting in React 19, you can use `use(Context)` instead of `useContext(Context)`, which allows you to read context in conditionals and loops. 

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

Successfully merging this pull request may close these issues.

[Suggestion]: Add a note to make developers more aware of use in the useContext page
3 participants