Expo Router
Expo Router is a popular routing library from Expo that is built on top of React Navigation. When using Unistyles with Expo Router, it’s necessary to configure it properly.
Modify main entry
Expo Router resolves routes differently that expected. Also, Unistyles 3.0 is parsing your StyleSheets
as soon as you import file containing it.
This combination may cause some issues. To prevent that you need to modify your main entry file:
Then, create index.js
file with following content:
With this setup, we will ensure that Unistyles is initialized before any other component.
Static rendering
If you’re using Expo Router with static rendering for the web, you also need to import the Unistyles initialization file in the +html.tsx
file:
It ensures that initialization of Unistyles is called whenever Expo Router tries to render next static page.