Skip to content

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

Open
karthik-awebon wants to merge 1 commit intoreactjs:mainfrom
karthik-awebon:note-about-use-in-usecontext-page
Open

Added a note about use in useContext page to make developers more aware of it.#7728
karthik-awebon wants to merge 1 commit intoreactjs:mainfrom
karthik-awebon:note-about-use-in-usecontext-page

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

Comments