我尝试在React Native中使用Styled Components创建全局样式。因此,我遵循了本教程https://scalablecss.com/styled-components-global-styles/,但出现以下错误
类型错误:(0,_$$_REQUIRE(...).createGlobalStyle)不是函数
我创建了一个名为globalStyles.js的文件:
import { createGlobalStyle } from 'styled-components';
const GlobalStyle = createGlobalStyle`
body {
margin: 0;
padding: 0;
background: black;
font-family: Open-Sans, Helvetica, Sans-Serif;
}
`;
export default GlobalStyle;
我导入GlobalStyle组件并将其放置在App.js中
import React from 'react';
import { Dimensions, SafeAreaView } from 'react-native';
import { ThemeProvider } from 'styled-components';
import Routes from './src/configuration/routes';
import theme from './src/configuration/theme';
import styled from 'styled-components';
import GlobalStyle from './src/configuration/globalStyles';
const App = () => {
return (
<SafeAreaView
style={{
width: '100%',
height: Dimensions.get('window').height,
}}>
<ThemeProvider theme={theme}>
<GlobalStyle />
<Routes />
</ThemeProvider>
</SafeAreaView>
);
};
export default App;
1条答案
按热度按时间jmo0nnb31#
在https://scalablecss.com/styled-components-global-styles/中,您可以找到:
请注意:此解决方案仅适用于Web,因此不适用于react-native!
请直接查看样式化组件文档。
声明需要这样完成: