Skip to content

Commit b1bc193

Browse files
authored
Document useContext bailout strategy (#1848)
1 parent ac4aa65 commit b1bc193

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

content/docs/hooks-reference.md

+2
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ Don't forget that the argument to `useContext` must be the *context object itsel
188188
* **Incorrect:** `useContext(MyContext.Consumer)`
189189
* **Incorrect:** `useContext(MyContext.Provider)`
190190

191+
A component calling `useContext` will always re-render when the context value changes. If re-rendering the component is expensive, you can [optimize it by using memoization](https://github.com/facebook/react/issues/15156#issuecomment-474590693).
192+
191193
>Tip
192194
>
193195
>If you're familiar with the context API before Hooks, `useContext(MyContext)` is equivalent to `static contextType = MyContext` in a class, or to `<MyContext.Consumer>`.

0 commit comments

Comments
 (0)