Attempted import error: 'inejectGlobal' is not exported from 'styled-components'.
错误是因为styled-components废弃injectGlobal这个API,更改为createGlobalStyle。用法如下:
1、在style.js中定义全局样式
import { createGlobalStyle } from 'styled-components';
export const GlobalStyle = createGlobalStyle`
body{
marigin: 0;
padding: 0;
background: green;
}
`
2、在App.js中引用
import React, { Component } from 'react';
import { GlobalStyle } from './style';
class App extends Component {
render() {
return (
<div className="App">
<GlobalStyle />
</div>
);
}
}
export default App;