forked from refinedev/refine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClientStyleContext.tsx
41 lines (34 loc) · 993 Bytes
/
ClientStyleContext.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import * as React from "react";
import { CacheProvider } from "@emotion/react";
import createCache from "@emotion/cache";
export interface ClientStyleContextData {
reset: () => void;
}
interface ClientCacheProviderProps {
children: React.ReactNode;
}
export const ClientStyleContext = React.createContext<ClientStyleContextData>({
// eslint-disable-next-line @typescript-eslint/no-empty-function
reset: () => {},
});
const createEmotionCache = () => {
return createCache({ key: "css" });
};
export const ClientStyleCacheProvider = ({
children,
}: ClientCacheProviderProps) => {
const [cache, setCache] = React.useState(createEmotionCache());
const clientStyleContextValue = React.useMemo(
() => ({
reset() {
setCache(createEmotionCache());
},
}),
[],
);
return (
<ClientStyleContext.Provider value={clientStyleContextValue}>
<CacheProvider value={cache}>{children}</CacheProvider>
</ClientStyleContext.Provider>
);
};