Skip to content

Commit 8677414

Browse files
Added a note about use in useContext page
1 parent e148ffe commit 8677414

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/content/reference/react/useContext.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ function Form() {
8282
```
8383
8484
It doesn't matter how many layers of components there are between the provider and the `Button`. When a `Button` *anywhere* inside of `Form` calls `useContext(ThemeContext)`, it will receive `"dark"` as the value.
85+
<Note>
86+
87+
[`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`.
88+
89+
</Note>
8590
8691
<Pitfall>
8792

0 commit comments

Comments
 (0)