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'
const App = () => {
// can be read from any storage eg. stan-js/MMKV/SQL
const { userTheme } = useStore()
// pass theme name to useInitialTheme hook
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)
return (
// your app's JSX
)
}