javascript - 用情感启用全球主题?
问题描述
我关注了https://github.com/emotion-js/emotion/issues/546,其中 Emotion 的作者 Kye 提到了一个解决方案,尽管我并不完全理解。
所以我做了一个小的CodeSandBox来实现问题中提供的细节。我怎样才能使background-color
主题工作injectGlobal
?
解决方案
使用情感 10 的人的更新:
import React from 'react'
import { useTheme, ThemeProvider } from 'emotion-theming'
import { css, Global } from '@emotion/core'
const GlobalStyles = () => {
const theme = useTheme()
return (
<Global styles={css`
body {
background: ${theme.bg};
}
`} />
)
}
const App = () => (
<ThemeProvider theme={{ bg: 'tomato' }}>
<main>
<h1>Hi</h1>
<GlobalStyles />
</main>
</ThemeProvider>
)
推荐阅读
- ruby-on-rails-5 - Rails 凭证在 Initializers 中不起作用的任何原因?
- java - 引起:java.lang.IllegalArgumentException: CONTAINING (1): [IsContaining, Containing, Contains]不支持redis查询派生-Redis
- javascript - 如何在按钮 onlick 上添加加载微调器
- javascript - 前端:Internet Explorer 问题
- ios - swift 4:在视图内将按钮的约束设置为安全区域
- reactjs - 如何通过 https 提供 reactjs 应用程序?
- swift - Xcode / 斯威夫特 | 将 TopBorder 添加到 TabBar
- javascript - 无法更新 fieldArray 元素
- reactjs - map() 函数错误。这个组件可以进一步改进吗
- python - 使用python从日志中提取和操作