Skip to content

Commit

Permalink
[examples] Wrap entire app with Styletron provider for with-styletron (
Browse files Browse the repository at this point in the history
  • Loading branch information
giraffesyo authored Feb 7, 2021
1 parent 958bd6c commit 1773b99
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
8 changes: 4 additions & 4 deletions examples/with-styletron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
22 changes: 15 additions & 7 deletions examples/with-styletron/pages/_document.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 1773b99

Please sign in to comment.