[英]Styled-components doesn't output style tag
I've set up a new project in React using Webpack, and wanted to give a try to Styled Components. 我已经使用Webpack在React中建立了一个新项目,并想尝试一下Styled Components。
My index.js looks like this: 我的index.js看起来像这样:
import React from "react"
import ReactDOM from "react-dom"
import Page from "./site/Page"
import styled from 'styled-components'
// Create a Title component that'll render an <h1> tag with some styles
const Title = styled.h1`
font-size: 1.5em;
text-align: center;
color: palevioletred;
`;
// Create a Wrapper component that'll render a <section> tag with some styles
const Wrapper = styled.section`
padding: 4em;
background: papayawhip;
`;
const Index = props => {
return (
<Page>
<Wrapper>
<Title>Test</Title>
</Wrapper>
</Page>);
};
ReactDOM.render(<Index/>, document.getElementById("app"))
The code outputted by styled-components on the HTML page looks fine but the <style>
the on the head doesn't get added, resulting in no css style at all. HTML页面上由styled-components输出的代码看起来不错,但是没有添加头部的
<style>
,因此根本没有CSS样式 。
<section class="sc-bwzfXH gzMTbA">
<h1 class="sc-bdVaJa bzmvhR">Test</h1>
</section>
Does somebody have any suggestions? 有人有什么建议吗?
Take a look at this API: CSSStyleSheet.insertRule() . 看一下这个API: CSSStyleSheet.insertRule() 。
Styled Components inserts empty style tags for hosting these dynamically injected styles. 样式化组件会插入空的样式标签,以托管这些动态注入的样式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.