diff --git a/.changeset/forty-pumas-refuse.md b/.changeset/forty-pumas-refuse.md new file mode 100644 index 000000000..b4d5232b9 --- /dev/null +++ b/.changeset/forty-pumas-refuse.md @@ -0,0 +1,5 @@ +--- +'@emotion/react': patch +--- + +Exposed `__unsafe_useEmotionCache` which can be used to access the current Emotion's cache in an easier way than before. Using this might break 0-config SSR and is not recommended to be used unless there you know what you are doing and you are OK with the mentioned downside. diff --git a/packages/react/src/context.js b/packages/react/src/context.js index af267ce29..0620fb9e0 100644 --- a/packages/react/src/context.js +++ b/packages/react/src/context.js @@ -20,6 +20,11 @@ let EmotionCacheContext: React.Context = export let CacheProvider = EmotionCacheContext.Provider +export let __unsafe_useEmotionCache = + function useEmotionCache(): EmotionCache | null { + return useContext(EmotionCacheContext) + } + let withEmotionCache = function withEmotionCache>( func: (props: Props, cache: EmotionCache, ref: Ref) => React.Node ): React.AbstractComponent { diff --git a/packages/react/src/index.js b/packages/react/src/index.js index 00e47ccff..5916634fe 100644 --- a/packages/react/src/index.js +++ b/packages/react/src/index.js @@ -1,7 +1,11 @@ // @flow import pkg from '../package.json' export type { SerializedStyles } from '@emotion/utils' -export { withEmotionCache, CacheProvider } from './context' +export { + withEmotionCache, + CacheProvider, + __unsafe_useEmotionCache +} from './context' export { jsx } from './jsx' export { jsx as createElement } from './jsx' export { Global } from './global'