Skip to content

Commit

Permalink
Added display names to public React contexts in development builds (#…
Browse files Browse the repository at this point in the history
…2428)

* feat: Add display names to public React contexts

* yarn changeset

* Update .changeset/olive-zebras-pump.md

Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
  • Loading branch information
eps1lon and Andarist committed Aug 8, 2021
1 parent 24557d9 commit a69929d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/olive-zebras-pump.md
@@ -0,0 +1,5 @@
---
'@emotion/react': patch
---

Added display names to public React contexts in development builds. This helps to recognize them in React Developer Tools.
4 changes: 4 additions & 0 deletions packages/react/src/context.js
Expand Up @@ -18,6 +18,10 @@ let EmotionCacheContext: React.Context<EmotionCache | null> =
: null
)

if (process.env.NODE_ENV !== 'production') {
EmotionCacheContext.displayName = 'EmotionCacheContext'
}

export let CacheProvider = EmotionCacheContext.Provider

export let __unsafe_useEmotionCache =
Expand Down
3 changes: 3 additions & 0 deletions packages/react/src/theming.js
Expand Up @@ -4,6 +4,9 @@ import weakMemoize from '@emotion/weak-memoize'
import hoistNonReactStatics from './isolated-hoist-non-react-statics-do-not-use-this-in-your-code'

export const ThemeContext = /* #__PURE__ */ React.createContext<Object>({})
if (process.env.NODE_ENV !== 'production') {
ThemeContext.displayName = 'EmotionThemeContext'
}

export const useTheme = () => React.useContext(ThemeContext)

Expand Down

0 comments on commit a69929d

Please sign in to comment.