Created
March 3, 2020 09:06
-
-
Save lxsmnsyc/72628beafe37dc8ac76749709d674969 to your computer and use it in GitHub Desktop.
Styletron SSR Setup wtih TypeScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Client, Server } from 'styletron-engine-atomic'; | |
import { DebugEngine } from 'styletron-react'; | |
function getHydratedClass(): HTMLStyleElement[] { | |
const els = document.getElementsByClassName('_styletron_hydrate_'); | |
const newEls = []; | |
for (let i = 0; i < els.length; i += 1) { | |
const el: Element = els[i]; | |
if (el instanceof HTMLStyleElement) { | |
newEls.push(el); | |
} | |
} | |
return newEls; | |
} | |
export const styletron = ( | |
(typeof window === 'undefined') | |
? new Server() | |
: new Client({ | |
hydrate: getHydratedClass(), | |
}) | |
); | |
export const debug = ( | |
process.env.NODE_ENV !== 'production' ? new DebugEngine() : undefined | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment