From 86774146e4c8e64d3b60660910d07a6de3f9862e Mon Sep 17 00:00:00 2001 From: Karthikeyan Balasubramanian Date: Tue, 8 Apr 2025 21:25:50 +0530 Subject: [PATCH] Added a note about use in useContext page --- src/content/reference/react/useContext.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/content/reference/react/useContext.md b/src/content/reference/react/useContext.md index ce06e7035d6..76894dbc4c3 100644 --- a/src/content/reference/react/useContext.md +++ b/src/content/reference/react/useContext.md @@ -82,6 +82,11 @@ function Form() { ``` 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. + + +[`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`. + +