Created
January 29, 2019 00:49
-
-
Save unyo/29df22ec751c00e98056b0074f456aa4 to your computer and use it in GitHub Desktop.
Remove gatsby FOUC (flash of unstyled content / text)
This file contains hidden or 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
// apparently there is some hidden settings at https://www.gatsbyjs.org/docs/debugging-replace-renderer-api/#fixing-the-replacerenderer-error | |
import React from "react" | |
import { renderToString } from "react-dom/server" | |
import { ServerStyleSheet, StyleSheetManager } from "styled-components" | |
export const replaceRenderer = ({ | |
bodyComponent, | |
replaceBodyHTMLString, | |
setHeadComponents, | |
}) => { | |
const sheet = new ServerStyleSheet() | |
const app = () => ( | |
<StyleSheetManager sheet={sheet.instance}> | |
{bodyComponent} | |
</StyleSheetManager> | |
) | |
replaceBodyHTMLString(renderToString(<app />)) | |
setHeadComponents([sheet.getStyleElement()]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment