繁体   English   中英

样式化组件 v5.3 createGlobalStyles 不工作

[英]Styled Component v5.3 createGlobalStyles not Working

我正在尝试使用 createGlobalStyles 为我的应用程序创建 Global Styles,但不知何故组件没有呈现,我收到控制台警告。

应用程序.js

import GlobalStyles from "./styles/GlobalStyles";

function App() {
  return (
    <div className="App">
      <GlobalStyles>
        <h1>This is a test line</h1>
      </GlobalStyles>
    </div>
  );
}

export default App;

GlobalStyles.js

import { createGlobalStyle } from "styled-components";

const GlobalStyles = createGlobalStyle`
html {
  font-size: 8px;
}
* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
  
  font-weight: 200;
}
body {
  font-size: 8px;
  
}
h1 {
    font-size: 2rem;
}

`;

export default GlobalStyles;

控制台错误[在此处输入图像描述][1]

GlobalStyle.js:28 The global style component sc-global-dtGiqY was given child JSX. createGlobalStyle does not render children.

错误截图

https://i.stack.imgur.com/QJBLz.png

<GlobalStyles />作为您其他内容的兄弟元素放置,而不是作为尝试接受子元素的父元素。

<div className="App">
  <GlobalStyles />
  <h1>This is a test line</h1>   
</div>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM