Last active
April 6, 2022 19:27
-
-
Save basarat/060bdf95ae8c46c62129f8c5b1bf4b88 to your computer and use it in GitHub Desktop.
nextjs-typestyle 🌹
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 App from 'next/app' | |
import { setStylesTarget } from 'typestyle' | |
export default class MyApp extends App { | |
componentDidMount() { | |
/** | |
* Hydrate typestyle | |
*/ | |
setStylesTarget(document.getElementById('styles-target')!) | |
} | |
} |
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 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>} | |
</> | |
) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you! It helped me