Skip to content

Instantly share code, notes, and snippets.

@basarat
Last active April 6, 2022 19:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save basarat/060bdf95ae8c46c62129f8c5b1bf4b88 to your computer and use it in GitHub Desktop.
Save basarat/060bdf95ae8c46c62129f8c5b1bf4b88 to your computer and use it in GitHub Desktop.
nextjs-typestyle 🌹
import App from 'next/app'
import { setStylesTarget } from 'typestyle'
export default class MyApp extends App {
componentDidMount() {
/**
* Hydrate typestyle
*/
setStylesTarget(document.getElementById('styles-target')!)
}
}
import Document from 'next/document';
import { getStyles } from 'typestyle';
export default class CustomDocument extends Document {
static async getInitialProps(ctx: any) {
const initialProps = await Document.getInitialProps(ctx)
return {
...initialProps,
styles: (
<>
{initialProps.styles}
{<style id='styles-target' dangerouslySetInnerHTML={{
__html: getStyles()
}}></style>}
</>
)
}
}
}
@smenshikov
Copy link

Thank you! It helped me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment