diff --git a/src/LazyHydrate.js b/src/LazyHydrate.js new file mode 100644 index 00000000..2e744582 --- /dev/null +++ b/src/LazyHydrate.js @@ -0,0 +1,164 @@ +import React, { useEffect, useState, useRef } from 'react' +import PropTypes from 'prop-types' + +import { StylesProvider, createGenerateClassName } from '@material-ui/core/styles' +import { SheetsRegistry } from 'jss' + +let registries = [] +const generateClassName = createGenerateClassName() + +export function clearLazyHydrateRegistries() { + registries = [] +} + +/* + This component renders the server side rendered stylesheets for the + lazy hydrated components. Once they become hydrated, these stylesheets + will be removed. +*/ +export function LazyStyleElements() { + return ( + <> + {registries.map((registry, index) => { + const id = `jss-lazy-${index}` + return