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

This commit is contained in:
Michael McQuade 2021-02-07 11:30:41 -06:00 committed by GitHub
parent 958bd6cabb
commit 1773b991bc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 11 deletions

View file

@ -8,10 +8,10 @@
},
"dependencies": {
"next": "latest",
"react": "^16.8.0",
"react-dom": "^16.8.0",
"styletron-engine-atomic": "^1.1.2",
"styletron-react": "^5.0.1"
"react": "17.0.1",
"react-dom": "17.0.1",
"styletron-engine-atomic": "1.4.6",
"styletron-react": "5.2.7"
},
"license": "MIT"
}

View file

@ -3,14 +3,22 @@ import { Provider as StyletronProvider } from 'styletron-react'
import { styletron } from '../styletron'
class MyDocument extends Document {
static getInitialProps(props) {
const page = props.renderPage((App) => (props) => (
<StyletronProvider value={styletron}>
<App {...props} />
</StyletronProvider>
))
static async getInitialProps(context) {
const renderPage = () =>
context.renderPage({
enhanceApp: (App) => (props) => (
<StyletronProvider value={styletron}>
<App {...props} />
</StyletronProvider>
),
})
const initialProps = await Document.getInitialProps({
...context,
renderPage,
})
const stylesheets = styletron.getStylesheets() || []
return { ...page, stylesheets }
return { ...initialProps, stylesheets }
}
render() {