-
Notifications
You must be signed in to change notification settings - Fork 9
Open
Description
一直在使用easywebpack,项目有场景在运行时对样式的操作/变量的传值,需要使用styled-component,但在server端进行renderToString收集好component的样式表,append进
import { renderToString } from 'react-dom/server'
import { ServerStyleSheet } from 'styled-components'
const sheet = new ServerStyleSheet()
try {
const html = renderToString(sheet.collectStyles(<YourApp />))
const styleTags = sheet.getStyleTags() // or sheet.getStyleElement();
} catch (error) {
// handle error
console.error(error)
} finally {
sheet.seal()
}
Metadata
Metadata
Assignees
Labels
No labels