@@ -4,7 +4,7 @@ import type { StylisPlugin } from '@emotion/cache';
4
4
import createCache from '@emotion/cache' ;
5
5
// eslint-disable-next-line no-restricted-imports
6
6
import { CacheProvider } from '@emotion/react' ;
7
- import React , { useEffect , useMemo , useState } from 'react' ;
7
+ import React , { useMemo } from 'react' ;
8
8
9
9
/**
10
10
* A Stylis plugin that wraps CSS rules in a CSS layer
@@ -59,21 +59,16 @@ type StyleCacheProviderProps = React.PropsWithChildren<{
59
59
* @returns A CacheProvider component with configured Emotion cache
60
60
*/
61
61
export const StyleCacheProvider = ( props : StyleCacheProviderProps ) => {
62
- const [ insertionPoint , setInsertionPoint ] = useState < HTMLElement | undefined > ( ) ;
63
-
64
- useEffect ( ( ) => {
65
- setInsertionPoint ( getInsertionPoint ( ) ) ;
66
- } , [ ] ) ;
67
-
68
62
const cache = useMemo ( ( ) => {
63
+ const insertionPoint = getInsertionPoint ( ) ;
69
64
return createCache ( {
70
65
key : 'cl-internal' ,
71
66
prepend : ! insertionPoint ,
72
67
insertionPoint : insertionPoint ?? undefined ,
73
68
nonce : props . nonce ,
74
69
stylisPlugins : props . cssLayerName ? [ wrapInLayer ( props . cssLayerName ) ] : undefined ,
75
70
} ) ;
76
- } , [ props . nonce , props . cssLayerName , insertionPoint ] ) ;
71
+ } , [ props . nonce , props . cssLayerName ] ) ;
77
72
78
73
return < CacheProvider value = { cache } > { props . children } </ CacheProvider > ;
79
74
} ;
0 commit comments