javascript - 启用带有情感的全局主题?

标签 javascript css reactjs styled-components emotion

我关注了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>
)

关于javascript - 启用带有情感的全局主题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51637950/

相关文章:

javascript - 类型错误 : Cannot read property 'name' of null in react with redux

javascript - 动画 HTML 列表下一个/上一个固定长度

javascript - 如何使用 JQuery 在 2 个元素之间画一条线并刷新该线?

javascript - React 组件在 onClick 事件后不会重新渲染

css - Mui LinearProgress Bar 停止显示在 display flex 上

html - 将文本放在图像旁边的 Bootstrap 行底部

javascript - 缓存动态网页(页面可能 99% 是静态的但包含一些动态内容)

javascript - Phonegap : Camera. getPicture 只返回 NATIVE_URI

html - 在网站上使用自定义 .ttf 字体

html - Flexbox( flex 方向 : column): wrapped child not positioned correctly when one child has fixed width