[英]Having problem to use global styles in styled-components
I'm trying to use the GlobalStyle to set-up some configurations for my SAP.我正在尝试使用 GlobalStyle 为我的 SAP 设置一些配置。 But i'm getting the following error:但我收到以下错误:
Error: Cannot create styled-component for component:
body {
color: "white";
}
My code (App.js):我的代码(App.js):
import React from 'react';
import createGlobalStyle from 'styled-components';
import MainContainer from './Components/MainContainer';
const GlobalStyle = createGlobalStyle`
body {
color: "white";
}
`;
function App() {
return (
<>
<GlobalStyle />
<MainContainer />
</>
);
}
export default App;
And in index.js, i'm using StrictMode:在 index.js 中,我使用的是 StrictMode:
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root'),
);
Solved, the error was in the import of createGlobalStyle, the correct line is:解决了,错误是在createGlobalStyle的导入中,正确的行是:
import { createGlobalStyle } from 'styled-components';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.