ThemeProvider error about Children

Open
#3,788 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
react-native, typescript
Domain
mobile

Research direction

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.

Written by the indexing model from the issue text.

Description

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>
Dominant language
MDX
Stars
25.9k
Forks
4.7k
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from react-native-elements/react-native-elements

All issues in react-native-elements/react-native-elements

Similar issues

More Mobile Dev issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.