mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
update styletron example (#5573)
This commit is contained in:
parent
27c0b199d0
commit
9ddc1d7b6f
|
@ -1,8 +0,0 @@
|
|||
import { StyletronProvider } from 'styletron-react'
|
||||
import getStyletron from './styletron'
|
||||
|
||||
export default ({ children }) => (
|
||||
<StyletronProvider styletron={getStyletron()}>
|
||||
{children}
|
||||
</StyletronProvider>
|
||||
)
|
|
@ -10,8 +10,8 @@
|
|||
"next": "latest",
|
||||
"react": "^16.0.0",
|
||||
"react-dom": "^16.0.0",
|
||||
"styletron-client": "^2.2.0",
|
||||
"styletron-react": "^2.2.1",
|
||||
"styletron-server": "^2.2.0"
|
||||
"styletron": "^3.0.4",
|
||||
"styletron-engine-atomic": "^1.0.8",
|
||||
"styletron-react": "^4.3.5"
|
||||
}
|
||||
}
|
||||
|
|
19
examples/with-styletron/pages/_app.js
Normal file
19
examples/with-styletron/pages/_app.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
import App, { Container } from 'next/app'
|
||||
import React from 'react'
|
||||
import { Provider as StyletronProvider } from 'styletron-react'
|
||||
import getStyletron from '../styletron'
|
||||
|
||||
class MyApp extends App {
|
||||
render () {
|
||||
const { Component } = this.props
|
||||
return (
|
||||
<Container>
|
||||
<StyletronProvider value={getStyletron()}>
|
||||
<Component />
|
||||
</StyletronProvider>
|
||||
</Container>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export default MyApp
|
|
@ -17,7 +17,7 @@ export default class MyDocument extends Document {
|
|||
<style
|
||||
className='_styletron_hydrate_'
|
||||
dangerouslySetInnerHTML={{ __html: sheet.css }}
|
||||
media={sheet.media || ''}
|
||||
media={sheet.media || null}
|
||||
key={i}
|
||||
/>
|
||||
))}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import { styled } from 'styletron-react'
|
||||
import Page from '../layout'
|
||||
|
||||
const Title = styled('div', {
|
||||
color: 'red',
|
||||
|
@ -7,7 +6,7 @@ const Title = styled('div', {
|
|||
})
|
||||
|
||||
export default () => (
|
||||
<Page>
|
||||
<div>
|
||||
<Title>My page</Title>
|
||||
</Page>
|
||||
</div>
|
||||
)
|
||||
|
|
|
@ -1,18 +1,16 @@
|
|||
|
||||
const isServer = typeof window === 'undefined'
|
||||
|
||||
let styletron
|
||||
|
||||
export default function getStyletron () {
|
||||
if (isServer) {
|
||||
const Styletron = require('styletron-server')
|
||||
if (isServer && !styletron) {
|
||||
const Styletron = require('styletron-engine-atomic').Server
|
||||
styletron = new Styletron()
|
||||
} else if (!styletron) {
|
||||
const Styletron = require('styletron-client')
|
||||
const Styletron = require('styletron-engine-atomic').Client
|
||||
const styleElements = document.getElementsByClassName('_styletron_hydrate_')
|
||||
styletron = new Styletron(styleElements)
|
||||
}
|
||||
|
||||
return styletron
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue