Created
May 19, 2020 08:12
-
-
Save dburles/122997990e41504e7733eb91db68f62e to your computer and use it in GitHub Desktop.
Next.js configuration for Mystical
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
import { MysticalProvider } from 'mystical'; | |
import PropTypes from 'prop-types'; | |
const App = ({ Component, pageProps, cache }) => { | |
return ( | |
<MysticalProvider cache={cache}> | |
<Component {...pageProps} /> | |
</MysticalProvider> | |
); | |
}; | |
App.propTypes = { | |
Component: PropTypes.elementType.isRequired, | |
pageProps: PropTypes.object, | |
cache: PropTypes.object, | |
}; | |
export default App; |
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
import { createCache } from 'mystical'; | |
import Document, { Head, Html, Main, NextScript } from 'next/document'; | |
class MyDocument extends Document { | |
static async getInitialProps(ctx) { | |
const cache = createCache(); | |
const originalRenderPage = ctx.renderPage; | |
ctx.renderPage = () => { | |
return originalRenderPage({ | |
enhanceApp(App) { | |
// eslint-disable-next-line react/display-name | |
return (props) => { | |
return <App {...props} cache={cache} />; | |
}; | |
}, | |
}); | |
}; | |
const initialProps = await Document.getInitialProps(ctx); | |
const { css, identifiers } = cache.getServerStyles(); | |
return { css, identifiers, ...initialProps }; | |
} | |
render() { | |
return ( | |
<Html> | |
<Head> | |
<style | |
id="__mystical__" | |
data-identifiers={this.props.identifiers.join(',')} | |
dangerouslySetInnerHTML={{ __html: this.props.css }} | |
/> | |
</Head> | |
<body> | |
<Main /> | |
<NextScript /> | |
</body> | |
</Html> | |
); | |
} | |
} | |
export default MyDocument; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment