Logo

dev-resources.site

for different kinds of informations.

React Native Expo with NativeWind v4 and Typescript

Published at
11/11/2024
Categories
expo
nativewindv4
reactnative
beginners
Author
y3asin
Author
6 person written this
y3asin
open
React Native Expo with NativeWind v4 and Typescript

I'm writing this because I faced the problem recently. When I was wasting my time, the solution was right in front of me in documentation.

Steps

Create an expo app

npx create-expo-app@latest
Enter fullscreen mode Exit fullscreen mode

this will create a template for your project.

NativeWind v4 installation

Step 1

Install nativewind in expo with necessary packages given in doc

npx expo install nativewind tailwindcss react-native-reanimated react-native-safe-area-context
Enter fullscreen mode Exit fullscreen mode

Step 2

then run

npx tailwindcss init
Enter fullscreen mode Exit fullscreen mode

this will create an tailwind.config.js file.
and paste this, also find it in documentation of nativewind v4

/** @type {import('tailwindcss').Config} */
module.exports = {
  // NOTE: Update this to include the paths to all of your component files.
  content: ["./app/**/*.{js,jsx,ts,tsx}"],
  presets: [require("nativewind/preset")],
  theme: {
    extend: {},
  },
  plugins: [],
}
Enter fullscreen mode Exit fullscreen mode

Step 3

Now, create a global.css file in root directory.

Step 4

Update babel.config.js. If you are using expo which is below 50 then follow expo below 49 sdk

module.exports = function (api) {
  api.cache(true);
  return {
    presets: [
      ["babel-preset-expo", { jsxImportSource: "nativewind" }],
      "nativewind/babel",
    ],
  };
};
Enter fullscreen mode Exit fullscreen mode

Step 5

Create metro.config.js if not have, then add this below codes. This is for Expo SDK 50+ only. If you are using expo which is below 50 then follow expo below 49 sdk

const { getDefaultConfig } = require("expo/metro-config");
const { withNativeWind } = require("nativewind/metro");

const config = getDefaultConfig(__dirname);

module.exports = withNativeWind(config, { input: "./global.css" });
Enter fullscreen mode Exit fullscreen mode

Step 6

Create an nativewind-env.d.ts file and add

/// <reference types="nativewind/types" />
Enter fullscreen mode Exit fullscreen mode

For the final step, import the global.css to the app/_laybout.tsx

import { Stack } from "expo-router";
import * as SplashScreen from "expo-splash-screen";
import "react-native-reanimated";

import "../global.css";

// Prevent the splash screen from auto-hiding before asset loading is complete.
SplashScreen.preventAutoHideAsync();

export default function RootLayout() {
  return (
    <Stack>
      <Stack.Screen name="index" options={{ headerShown: false }} />
    </Stack>
  );
}
Enter fullscreen mode Exit fullscreen mode

Now, tailwindcss is working in your react native expo project with NativeWind v4.

import React from "react";
import { Text } from "react-native";
import { SafeAreaView } from "react-native-safe-area-context";

const App = () => {
  return (
    <SafeAreaView>
      <Text className="text-blue-600 font-bold text-3xl ">
        Creating app with expo
      </Text>

    </SafeAreaView>
  );
};

export default App;
Enter fullscreen mode Exit fullscreen mode

Working...

Image description

Note: All these are written in the Official documentation of NativeWind. I just wanted to keep them here, so that no newbie face the problem like me and waste their precious time.

expo Article's
30 articles in total
Favicon
Read Text Asset File in Expo
Favicon
Run Storybook with NX Expo and React Native Paper
Favicon
Explorando Notificações Push no React Native com Expo e OneSignal!
Favicon
Starting React Native Project in 2025
Favicon
Guia Completo: Como Integrar WatermelonDB no React Native 0.76 com Expo 52 e TypeScript
Favicon
How to create authenticated routes with the new Expo SDK 51 using Expo Router
Favicon
React Native Expo with NativeWind v4 and Typescript
Favicon
Translate & Guess: Build a Flag Quiz with Expo and Tolgee
Favicon
How i implemented my server login screen for Mastodon
Favicon
How to Change iOS Push Notifications Permission Dialog with Expo
Favicon
Exploring React Native Navigation with Expo: A Complete Guide
Favicon
How to Render OpenStreetMap in an Expo React Native Web App Using React Leaflet
Favicon
EAS build reads your .gitignore file
Favicon
#2 - Expo apk keeps on crashing after build
Favicon
Dear expo, who are you?
Favicon
npm i openai-react-native
Favicon
Expo51 Jotai Template + flashlist + tamagui
Favicon
Scroll-Responsive Animated Header Bar with Expo Router
Favicon
Expo vs. React Native: Pros, Cons, and Key Differences
Favicon
To Obfuscate or Not Obfuscate (React Native)
Favicon
How to disable keyboard suggestions for Android in React Native
Favicon
Expo51 Jotai Template, ready to use
Favicon
Let's get started with React Native + Expo
Favicon
Generar APK con EAS ⚛️ React Native
Favicon
How to publish your React Native app to Expo Store 2024
Favicon
Creating a WebView app in React Native using Expo
Favicon
Embracing Expo: The New Standard for Creating React Native Apps
Favicon
Automate Your Expo Builds with EAS Using GitHub Actions: A Step-by-Step Guide (Android)
Favicon
How to Generate APK Using React Native Expo
Favicon
Creating Chat Bubbles with curls in React Native (svg)

Featured ones: