Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

React native Appearance color scheme returns undefined

$
0
0

I'm trying to change the theme of a react native app. The idea is when a user changes the system theme on their device its automatically detects the changes and updates the UI accordingly. The example below returns as undefined when using typescript but with normal JS it works as intended.

Links used as references supplied

https://callstack.github.io/react-native-paper/theming.html
https://reactnative.dev/docs/appearance
https://dev.to/magoacademico/dark-theme-com-react-navigation-typescript-react-native-paper-55ob

const Main: FC = () => {  let theme = Appearance.getColorScheme();  let colorTheme;  const toggleTheme = useCallback((appTheme: any) => {    colorTheme = theme === 'light' ? lightTheme : darkTheme;  }, []);  useEffect(() => {    Appearance.addChangeListener(({ colorScheme }) => {      toggleTheme(colorScheme);    });  }, [toggleTheme]);  console.log(colorTheme);  return (<NavigationContainer><PaperProvider theme={colorTheme}><App /></PaperProvider></NavigationContainer>  );};

Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>