Tamagui and One go together so well you'd swear they were made by the same person. When targeting both native and web, and wanting to share UI, you don't have many options.
Tamagui does many things that no other universal libraries do: all of it's features work with SSR without flashing of styles, it supports spring and CSS animations (also SSR safe), it supports light and dark mode (also SSR safe), it's fully type safe, it supports container queries, and it outputs nearly ideal code for each platform.
npx one
.We're going to support SSR-safe light and dark mode with @vxrn/color-scheme
:
npm install tamagui @tamagui/config @tamagui/vite-plugin @vxrn/color-scheme
Be sure to check out the Dark mode guide for more detail there.
Next, update your root _layout.tsx
:
app/_layout.tsx
And add your config/tamagui.config.ts
:
config/tamagui.config.ts
The reason we separate this file out is that it lets the Tamagui compiler optimize things. You don't have to do this, but it's pretty easy.
This preset config we recommend as it lets you just get working on your app, but if you want a custom configuration, the npx one
starter has a nice custom configuration example.
Next for the Vite plugin. You don't need to set up the Tamagui Vite plugin, but even if not using the optimizing compiler, it adds a lot of nice stuff: debug attributes, broader react-native compatibility, and the optimizing compiler.
vite.config.ts
If you want to optimize things a bit further, we can output the Tamagui design system CSS to a stylesheet by changing our plugin configuration:
vite.config.ts
And then changing our root layout to add disableInjectCSS
, and instead importing the CSS at the top:
app/_layout.tsx
That should be about it! You now have SSR safe styling, light and dark mode, and a bunch of advanced styling features.
Check out the Tamagui site for a lot documentation.
Edit this page on GitHub.