全局样式

Emotion中的全局样式是通过<Global>组件来设置的,<Global>组件使用styles属性来接收要设定的样式,可以将css生成的样式直接赋予styles,或者将对象样式赋予styles<Global>在使用的时候,可以仿照以下示例。

import { Global, jsx } from '@emotion/react'; function App() { return ( <div> <Global styles={css` h1 { font-weight: 700; } `} /> <Global styles={{ '.some-class': { fontWeight: 700 } }} /> <div className="some-class">Some text</div> </div> ); }

Warning

<Global>组件只是在全局插入样式,当样式更改或者<Global>组件被卸载的时候,全局样式也会被删除。