React Native 类型错误:(0,_$$_REQUIRE(...).createGlobalStyle)不是函数

t40tm48m  于 2022-11-25  发布在  React
关注(0)|答案(1)|浏览(103)

我尝试在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;
jmo0nnb3

jmo0nnb31#

https://scalablecss.com/styled-components-global-styles/中,您可以找到:
请注意:此解决方案仅适用于Web,因此不适用于react-native!
请直接查看样式化组件文档。
声明需要这样完成:

declare module 'styled-components/native' {
  export interface DefaultTheme {
    borderRadius: string;

    colors: {
      main: string;
      secondary: string;
    };
  }
}

相关问题