From 24557d9d6409db453fdbaa031cb635820305f137 Mon Sep 17 00:00:00 2001 From: Joseph Garrone Date: Sun, 8 Aug 2021 10:42:02 +0200 Subject: [PATCH] Exposed `__unsafe_useEmotionCache` from `@emotion/react` (#2441) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * expose __unsafe_useEmotionCache from @emotion/react * Upgrade Changesets * Update .changeset/forty-pumas-refuse.md Co-authored-by: Mateusz BurzyƄski --- .changeset/forty-pumas-refuse.md | 5 +++++ packages/react/src/context.js | 5 +++++ packages/react/src/index.js | 6 +++++- 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 .changeset/forty-pumas-refuse.md 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'