How to create simple switch toggle to switch between dark theme and light theme in react native
I am creating a simple switch component that is if turned on the theme of the app will be light otherwise it would be dark.
Here is what i tried but it is not working. How can i make the toggle switch the theme of the whole app?
import { StatusBar } from 'expo-status-bar';
import React, {useState} from 'react';
import { StyleSheet, Text, View, Switch, Appearance } from 'react-native';
export default function App() {
const [isEnabled, setIsEnabled] = useState(false);
const toggleSwitch = () => setIsEnabled(previousState => !previousState);
const colorScheme = Appearance.getColorScheme();
if (colorScheme === 'dark') {
}
return (
);
}