styled-components中弃用injectGlobal的解决

styled-components中弃用injectGlobal的解决1

编译错误提示: injectGlobal' is not exported from 'styled-components
原因: styled-components 4.x版本将原来的injectGlobal方法用createGlobalStyle替换了。用法上也有一些不同,如下

import {createGlobalStyle} from 'styled-components';
export const GlobalStyled = createGlobalStyle`
body{
    margin:0;
    padding:0;
    background:red;
}`
import React from 'react';
import {GlobalStyled} from './style.js';
class App extends React.Components{
	render(){
	    return(
	        <div className='App'>
	            <GlobalStyled />
	        </div>
	    )
	}
}

  1. 转自:https://blog.csdn.net/GoldenLegs/article/details/87451827 ↩︎

发布了11 篇原创文章 · 获赞 9 · 访问量 2456

猜你喜欢

转载自blog.csdn.net/weixin_43553694/article/details/97113860
今日推荐