ThemeProvider error about Children

Đang mở
#3,788 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
42/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
react-native, typescript
Lĩnh vực
mobile

Hướng nghiên cứu

Start with the provided TSX entry code and reproduce the TypeScript warning when ThemeProvider receives the theme prop. Trace the ThemeProvider prop type definitions and verify that children is accepted in this usage; done means the reproduction type-checks without the reported error.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

pkg: themed
Is there an existing issue for this?
  • I have searched the existing issues
Explain what you did

Issue https://github.com/react-native-elements/react-native-elements/issues/3452 is marked closed. I am starting a new project today and when I wrap theThemeProvider at the top level, I get a TS warning about the children.

I am just trying to get the dark mode toggle to work, so I am adding ThemeProvider

This error appears only after I add the theme prop. Without the theme prop, there is no error.

Expected behavior

ThemeProvider props have children as expected prop with or without the theme prop.

Describe the bug

When I include the theme prop only is when I see the bug:

Type '{ children: Element; theme: CreateThemeOptions; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes & Pick<Readonly, never> & InexactPartial<...> & InexactPartial<...>'.
Property 'children' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes & Pick<Readonly, never> & InexactPartial<...> & InexactPartial<...>'.ts(2322)

Steps To Reproduce
this entry code:



import {
  createTheme,
  darkColors,
  lightColors,
  useThemeMode,
} from '@rneui/themed';
import { StatusBar } from 'expo-status-bar';
import React, { useState } from 'react';
import { Platform, View } from 'react-native';
import { ColorSchemeName, useColorScheme } from 'react-native-appearance';
import { ThemeProvider, useTheme } from 'react-native-elements';
import { SafeAreaProvider } from 'react-native-safe-area-context';

const theme = createTheme({
  lightColors: {
    ...Platform.select({
      default: lightColors.platform.android,
      ios: lightColors.platform.ios,
    }),
  },
  darkColors: {
    ...Platform.select({
      default: darkColors.platform.android,
      ios: darkColors.platform.ios,
    }),
  },
});

const ColorScheme = ({ children }) => {
  const [mode, setMode] = useState<ColorSchemeName>();
  const colorMode = useColorScheme();
  const { theme } = useTheme();

  React.useEffect(() => {
    setMode(colorMode);
  }, [colorMode]);

  return (
    <View
      style={{ backgroundColor: theme.colors?.platform?.default as string }}
    >
      {children}
    </View>
  );
};

export default function App() {
  console.log(theme);

  return (
    <SafeAreaProvider>
      <ThemeProvider theme={theme}>
        <ColorScheme>
          <StatusBar style="auto" />
        </ColorScheme>
      </ThemeProvider>
    </SafeAreaProvider>
  );
}


### Screenshots

<img width="816" alt="image" src="https://github.com/react-native-elements/react-native-elements/assets/15162169/9a1e513e-9333-47b2-aa9b-796bb2072df0">


### Your Environment

<details>
<summary>`npx @rneui/envinfo`</summary>

      ```
React Native Elements Env Info

## Global Dependencies:

   No related dependency found

## Local Dependencies:

 - @rneui/base : ^0.0.0-edge.2
 - @rneui/themed : ^0.0.0-edge.2
 - expo : ~48.0.15
 - react : 18.2.0
 - react-native : 0.71.7
 - react-native-elements : ^3.4.3      ```

</details>
Ngôn ngữ chính
MDX
Star
25.9k
Fork
4.7k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của react-native-elements/react-native-elements

Tất cả issue của react-native-elements/react-native-elements

Issue tương tự

Thêm issue về Mobile Dev

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.