mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
update with-fela to Fela > 5.0 (#2253)
* update fela example * fix wrong whitespace
This commit is contained in:
parent
480f3ab124
commit
c72435fe5c
|
@ -3,14 +3,6 @@ import { createRenderer } from 'fela'
|
|||
// add your renderer configuration here
|
||||
const renderer = createRenderer()
|
||||
|
||||
export function getRenderer () {
|
||||
export default function getRenderer () {
|
||||
return renderer
|
||||
}
|
||||
|
||||
export function getMountNode () {
|
||||
if (typeof window !== 'undefined') {
|
||||
return document.getElementById('fela-stylesheet')
|
||||
}
|
||||
|
||||
return undefined
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { Provider } from 'react-fela'
|
||||
import { getRenderer, getMountNode } from './fela'
|
||||
import getRenderer from './fela'
|
||||
|
||||
export default ({ children }) => (
|
||||
<Provider renderer={getRenderer()} mountNode={getMountNode()}>
|
||||
<Provider renderer={getRenderer()}>
|
||||
{children}
|
||||
</Provider>
|
||||
)
|
||||
|
|
|
@ -7,10 +7,11 @@
|
|||
"start": "next start"
|
||||
},
|
||||
"dependencies": {
|
||||
"fela": "^4.1.2",
|
||||
"fela": "^5.0.1",
|
||||
"fela-dom": "5.0.2",
|
||||
"next": "latest",
|
||||
"react": "^15.4.2",
|
||||
"react-dom": "^15.4.2",
|
||||
"react-fela": "^4.1.2"
|
||||
"react-fela": "^5.0.2"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,29 +1,31 @@
|
|||
import Document, { Head, Main, NextScript } from 'next/document'
|
||||
import { getRenderer } from '../fela'
|
||||
import { renderToSheetList } from 'fela-dom'
|
||||
import getRenderer from '../fela'
|
||||
|
||||
export default class MyDocument extends Document {
|
||||
static getInitialProps ({ renderPage }) {
|
||||
const page = renderPage()
|
||||
const renderer = getRenderer()
|
||||
const css = renderer.renderToString()
|
||||
|
||||
const sheetList = renderToSheetList(renderer)
|
||||
renderer.clear()
|
||||
|
||||
return {
|
||||
...page,
|
||||
css
|
||||
sheetList
|
||||
}
|
||||
}
|
||||
|
||||
render () {
|
||||
const styleNodes = this.props.sheetList.map(({ type, media, css }) => (
|
||||
<style data-fela-type={type} media={media}>{css}</style>
|
||||
))
|
||||
|
||||
return (
|
||||
<html>
|
||||
<Head>
|
||||
<title>My page</title>
|
||||
<style
|
||||
dangerouslySetInnerHTML={{ __html: this.props.css }}
|
||||
id='fela-stylesheet'
|
||||
/>
|
||||
{styleNodes}
|
||||
</Head>
|
||||
<body>
|
||||
<Main />
|
||||
|
|
Loading…
Reference in a new issue