【发布时间】:2021-10-26 14:15:30
【问题描述】:
我现在开始学习下一步。我对如何在框架中应用样式化组件的 createGlobalStyle 功能有点迷茫。
【问题讨论】:
标签: reactjs next.js styled-components
我现在开始学习下一步。我对如何在框架中应用样式化组件的 createGlobalStyle 功能有点迷茫。
【问题讨论】:
标签: reactjs next.js styled-components
只需转到Vercel github 并安装:
npx create-next-app --example with-styled-components with-styled-components-app
# or
yarn create next-app --example with-styled-components with-styled-components-app
【讨论】:
您可以通过在 pages 目录中创建 _app.js 文件来使用自定义应用程序
import { createGlobalStyle } from 'styled-components'
const GlobalStyle = createGlobalStyle`
body {
color: ${props => (props.whiteColor ? 'white' : 'black')};
}
`
function MyApp({ Component, pageProps }) {
return <><GlobalStyle whiteColor /><Component {...pageProps} /></>
}
export default MyApp
【讨论】:
import { GlobalStyles } from '../../GlobalStyles' function MyApp({ Component, pageProps }) { return ( <> <GlobalStyles /> <Component {...pageProps} /> </> ) } export default MyApp