We've all been there—you're working on a React Native project, trying to apply styles with NativeWind, and everything looks perfect in the code. But when you check the app, the styles just don't seem to work. Frustrating, right? In this post, I'll walk you through a quirky issue I faced when developing a native app in the browser's inspection mode, and how a simple solution got my styles back on track.
I was too lazy to open the simulator, so I used the browser's inspection mode for native app development. However, when I wrote the following code, the styles didn't apply as expected:
import { Link } from "expo-router";
import { StatusBar } from "expo-status-bar";
import { Text, View } from "react-native";
export default function App() {
return (
<View className="bg-gray-100 flex-1 items-center justify-center">
<Text className="text-2xl">Shoot!</Text>
<StatusBar style="auto" />
<Link href="/profile">Go to Profile</Link>
</View>
);
}
The weirdest part was that the following code worked without issues:
import { Link } from "expo-router";
import { StatusBar } from "expo-status-bar";
import { Text, View } from "react-native";
export default function App() {
return (
<View className="bg-gray-100">
<Text className="text-2xl">Shoot!</Text>
<StatusBar style="auto" />
<Link href="/profile">Go to Profile</Link>
</View>
);
}
To ensure that this setup applies to all components, insert the following code in the _layout.tsx
file:
import { NativeWindStyleSheet } from "nativewind";
NativeWindStyleSheet.setOutput({
default: "native",
});