Skip to content

Commit

Permalink
Exposed __unsafe_useEmotionCache from @emotion/react (#2441)
Browse files Browse the repository at this point in the history
* expose __unsafe_useEmotionCache from @emotion/react

* Upgrade Changesets

* Update .changeset/forty-pumas-refuse.md

Co-authored-by: Mateusz Burzyński <[email protected]>
  • Loading branch information
garronej and Andarist authored Aug 8, 2021
1 parent dcc72d0 commit 24557d9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/forty-pumas-refuse.md
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 5 additions & 0 deletions packages/react/src/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ let EmotionCacheContext: React.Context<EmotionCache | null> =

export let CacheProvider = EmotionCacheContext.Provider

export let __unsafe_useEmotionCache =
function useEmotionCache(): EmotionCache | null {
return useContext(EmotionCacheContext)
}

let withEmotionCache = function withEmotionCache<Props, Ref: React.Ref<*>>(
func: (props: Props, cache: EmotionCache, ref: Ref) => React.Node
): React.AbstractComponent<Props> {
Expand Down
6 changes: 5 additions & 1 deletion packages/react/src/index.js
Original file line number Diff line number Diff line change
@@ -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'
Expand Down

0 comments on commit 24557d9

Please sign in to comment.