Unverified Commit 1773b991 authored by Michael McQuade's avatar Michael McQuade Committed by GitHub

[examples] Wrap entire app with Styletron provider for with-styletron (#21908)

parent 958bd6ca
...@@ -8,10 +8,10 @@ ...@@ -8,10 +8,10 @@
}, },
"dependencies": { "dependencies": {
"next": "latest", "next": "latest",
"react": "^16.8.0", "react": "17.0.1",
"react-dom": "^16.8.0", "react-dom": "17.0.1",
"styletron-engine-atomic": "^1.1.2", "styletron-engine-atomic": "1.4.6",
"styletron-react": "^5.0.1" "styletron-react": "5.2.7"
}, },
"license": "MIT" "license": "MIT"
} }
...@@ -3,14 +3,22 @@ import { Provider as StyletronProvider } from 'styletron-react' ...@@ -3,14 +3,22 @@ import { Provider as StyletronProvider } from 'styletron-react'
import { styletron } from '../styletron' import { styletron } from '../styletron'
class MyDocument extends Document { class MyDocument extends Document {
static getInitialProps(props) { static async getInitialProps(context) {
const page = props.renderPage((App) => (props) => ( const renderPage = () =>
<StyletronProvider value={styletron}> context.renderPage({
<App {...props} /> enhanceApp: (App) => (props) => (
</StyletronProvider> <StyletronProvider value={styletron}>
)) <App {...props} />
</StyletronProvider>
),
})
const initialProps = await Document.getInitialProps({
...context,
renderPage,
})
const stylesheets = styletron.getStylesheets() || [] const stylesheets = styletron.getStylesheets() || []
return { ...page, stylesheets } return { ...initialProps, stylesheets }
} }
render() { render() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment