Skip to content

Commit 6c16abc

Browse files
committed
docs(useContext): explain separate providers in troubleshooting
1 parent 2639f36 commit 6c16abc

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

‎src/content/reference/react/useContext.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,7 @@ There are a few common ways that this can happen:
13521352
1. You're rendering `<SomeContext>` in the same component (or below) as where you're calling `useContext()`. Move `<SomeContext>` *above and outside* the component calling `useContext()`.
13531353
2. You may have forgotten to wrap your component with `<SomeContext>`, or you might have put it in a different part of the tree than you thought. Check whether the hierarchy is right using [React DevTools.](/learn/react-developer-tools)
13541354
3. You might be running into some build issue with your tooling that causes `SomeContext` as seen from the providing component and `SomeContext` as seen by the reading component to be two different objects. This can happen if you use symlinks, for example. You can verify this by assigning them to globals like `window.SomeContext1` and `window.SomeContext2` and then checking whether `window.SomeContext1 === window.SomeContext2` in the console. If they're not the same, fix that issue on the build tool level.
1355+
4. You might have two separate providers of the same context. Each `<SomeContext>` provider has its own independent value, so components inside one provider won't see updates from another. If both trees need the same value, render a single provider above both of them.
13551356
13561357
### I am always getting `undefined` from my context although the default value is different {/*i-am-always-getting-undefined-from-my-context-although-the-default-value-is-different*/}
13571358

0 commit comments

Comments
 (0)