0.0.1 • Published 7 years ago
react-document-style v0.0.1
react-document-style
We could render style component either client or server side via react-side-effect
.
- UMD unpak
Usage
The Component writing like here.
import Style from 'react-document-style'
const css = 'body { color: red; }'
export default () => (
<Style css={css}>
<div>
Hi
<Style css={'div { color: blue; }'}/>
</div>
</Style>
)
- Client
Would create a style DOM inhead
<head>
<style type="text/css">
body { color: red; }
div { color: blue; }
</style>
</head>
- Server
Callrewind
orpeek
to get the css string on server side after render component.
please see the doc about react-side-effect for more information
ReactServerDOM.renderToString(<Style css={'div { color: blue; }'}/>)
Style.peek() // div { color: blue; }
Style.rewind() // div { color: blue; }
Style.peek() // undefined