How to retrieve the name of the theme saved by the user in async storage and set it as the app's theme. #202
Replies: 3 comments 4 replies
-
What's your use case? Why do you save theme to storage? You can always retrieve it from useStyles hook. If you need to define user theme then you can use this function: https://reactnativeunistyles.vercel.app/reference/theming/#update-theme-during-runtime |
Beta Was this translation helpful? Give feedback.
-
You need to import |
Beta Was this translation helpful? Give feedback.
-
I solve my problem with Double Question Marks, //in unistyles.ts file: const getInitialTheme = getItem('defaultTheme') ?? 'light'; .addConfig({ This allows the user to set their favorite theme, and save this information in MMKV, even after the user closes the application and opens it again, the favorite theme is still set and applied. |
Beta Was this translation helpful? Give feedback.
-
I save the theme that the user defined in async storage but I don't know how to retrieve it later so that the theme chosen by the user can always be set until they change it. How to do this in React Native unistyles?
my unistyles.ts file:
import {UnistylesRegistry} from 'react-native-unistyles';
import {breakpoints} from './breakpoints';
import {lightTheme, darkTheme} from './themes';
type AppBreakpoints = typeof breakpoints;
type AppThemes = {
light: typeof lightTheme;
dark: typeof darkTheme;
};
declare module 'react-native-unistyles' {
export interface UnistylesBreakpoints extends AppBreakpoints {}
export interface UnistylesThemes extends AppThemes {}
}
UnistylesRegistry.addBreakpoints(breakpoints)
.addThemes({
light: lightTheme,
dark: darkTheme,
})
.addConfig({
adaptiveThemes: true,
});
Beta Was this translation helpful? Give feedback.
All reactions