Skip to content

useInitialTheme

useInitialTheme
All platforms
2.0.0

This hook is optional, but its use is required under certain circumstances, as described in the theming guide.

If you’re using multiple themes and need to determine the initial theme during runtime, this hook is necessary to select the initial theme.

import { useInitialTheme, useStyles } from 'react-native-unistyles'
// can be read from any storage eg. MMKV/SQL/FileSystem/Appearance
const userTheme = ...
useInitialTheme(userTheme)
// useInitialTheme must be called before the first useStyles hook
// it's so fast that you can even call it in the same component!
const { styles } = useStyles(stylesheet)