Skip to content

Commit de519c9

Browse files
authored
Merge pull request #916 from jpudysz/feature/docs
docs: add explanation about theme access in StyleSheet.create API and web error
2 parents cb5e4e1 + 181421f commit de519c9

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

docs/src/content/docs/v3/tutorial/cleanup-screens.mdx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,20 @@ const styles = StyleSheet.create(theme => ({
139139
}));
140140
```
141141

142+
<Aside title="Accessing the Theme">
143+
Have you noticed how we access the theme object?
144+
145+
```tsx /theme/
146+
const styles = StyleSheet.create(theme => ({ ... }))
147+
```
148+
149+
This approach is slightly different from the standard React Native `StyleSheet.create` API.
150+
With Unistyles, your `StyleSheet.create` function will be automatically re-invoked whenever the theme changes, ensuring your styles are always up-to-date.
151+
152+
**If you're following the tutorial on the web, you might see an error because additional configuration is required for web support.
153+
For now, focus on iOS. We'll show you how to get it working on the web later.**
154+
</Aside>
155+
142156
The most interesting file here is `_layout.tsx`, which configures the `Tabs` navigator. The default code uses the `useColorScheme` hook to dynamically set the `tabBarActiveTintColor`.
143157
Since `@react-navigation` components aren't aware of the Unistyles C++ core, they can't be updated automatically. We need a way to get the current theme data into our component and trigger a re-render when the theme changes.
144158
This is the perfect use case for the `useUnistyles` hook. It subscribes the component to theme changes, giving you access to the theme object and ensuring the component re-renders when the theme is updated.

0 commit comments

Comments
 (0)