entry.client.tsx 909 B

123456789101112131415161718192021222324252627282930313233
  1. import * as React from 'react';
  2. import {hydrate} from 'react-dom';
  3. import {CacheProvider} from '@emotion/react';
  4. import {RemixBrowser} from '@remix-run/react';
  5. import ClientStyleContext from './styles/client.context';
  6. import createEmotionCache from './styles/createEmotionCache';
  7. interface ClientCacheProviderProps {
  8. children: React.ReactNode;
  9. }
  10. // might work to inject styles but we are currently pulling CSS from CDN
  11. function ClientCacheProvider({children}: ClientCacheProviderProps) {
  12. const [cache, setCache] = React.useState(createEmotionCache());
  13. const reset = React.useCallback(() => {
  14. setCache(createEmotionCache());
  15. }, []);
  16. return (
  17. <ClientStyleContext.Provider value={{reset}}>
  18. <CacheProvider value={cache}>{children}</CacheProvider>
  19. </ClientStyleContext.Provider>
  20. );
  21. }
  22. hydrate(
  23. <ClientCacheProvider>
  24. <RemixBrowser />
  25. </ClientCacheProvider>,
  26. document
  27. );