Next.js
yarn add @emotion/serverimport BaseDocument from "next/document";
import { withEmotionCache } from "tss-react/nextJs";
import { createMuiCache } from "./index";
export default withEmotionCache({
//If you have a custom document pass it instead
"Document": BaseDocument,
//Every emotion cache used in the app should be provided.
//Caches for MUI should use "prepend": true.
"getCaches": ()=> [ createMuiCache() ]
});import type { EmotionCache } from "@emotion/cache";
import { CacheProvider } from "@emotion/react";
import createCache from "@emotion/cache";
let muiCache: EmotionCache | undefined = undefined;
export const createMuiCache = () =>
muiCache = createCache({
"key": "mui",
"prepend": true
});
export default function Index() {
return (
<CacheProvider value={muiCache ?? createMuiCache()}>
{/* Your app */}
</CacheProvider>
);
}Last updated
Was this helpful?