react之4.X版本的styled-components弃用injectGlobal变为createGlobalStyle

版权声明:初心 - 杨瑞超个人博客整理,转载请注明出处: https://blog.csdn.net/qq_42817227/article/details/85608073

初心-杨瑞超个人博客诚邀您加入qq群(IT-程序猿-技术交流群): 757345416丨(IT-程序猿-技术交流2群): 936929828

代码:

import { injectGlobal } from 'styled-components';

injectGlobal`
body {
  margin: 0;
  padding: 0;
}
`

报错信息展示:
在这里插入图片描述
说明:
在styled-component 4.X版本中injectGlobal API除去,取而代之的是createGlobalStyle样式组件。

也就是说以前的 injectGlobal 全局样式在4.X版本代替为使用 createGlobalStyle 渲染组件的方式来使用全局样式。

官方文档说明:https://www.styled-components.com/docs/api

附官方说明:The injectGlobal API was removed and replaced by createGlobalStyle in styled-components v4.

猜你喜欢

转载自blog.csdn.net/qq_42817227/article/details/85608073
今日推荐