[英]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.
錯誤截圖
將<GlobalStyles />
作為您其他內容的兄弟元素放置,而不是作為嘗試接受子元素的父元素。
<div className="App">
<GlobalStyles />
<h1>This is a test line</h1>
</div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.