react-native-elements
react-native-elements copied to clipboard
ThemeProvider error about Children
Is there an existing issue for this?
- [X] 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<ThemeProvider> & Pick<Readonly<ThemeProviderProps>, never> & InexactPartial<...> & InexactPartial<...>'. Property 'children' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<ThemeProvider> & Pick<Readonly<ThemeProviderProps>, 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>
type ExistingThemeProviderProps = ComponentProps<typeof ThemeProvider> & {children: ReactNode};
const ThemeProviderExtended = (props: ExistingThemeProviderProps) => <ThemeProvider {...props}/>
This simple wrapper fixes the issue for me for now, once RNE team releases the type fix this can be removed.