TypeScript icon, indicating that this package has built-in type declarations

0.0.18 • Public • Published

react-native-tailwindcss npm version

Use tailwindcss in react-native project


npm install @tingyuan/react-native-tailwindcss --save-dev


  1. Run npx tailwindcss init if tailwind.config.js does not exist. (see installation).

  2. Add the babel plugin to babel.config.js.

    module.exports = function (api) {
      return {
        presets: ['babel-preset-expo'],
        plugins: ['@tingyuan/react-native-tailwindcss/babel'],
  3. Start tailwindcss watch task.

for development, run:

npx react-native-tailwindcss-start

for build, run this before the building app command:

npx react-native-tailwindcss-build


function App(props: { textColor: string }) {
  const renderItem = ({ item }) => <Text>{item.title}</Text>
  return (
    <View className="flex-1 flex-row h-full">
      <Text className="font-bold text-green-500 text-lg" style={{ color: props.textColor }}>
        Hello Tailwindcss
        contentContainerStyle={tw('px-3 bg-slate-500')}

jsx attribute className will be transformed to style and tw('') will be transformed to style object.

TypeScript support

To support infer global tw helper function type and className jsx attribute, you can:

add three slash directive in a .d.ts file:

/// <reference types="@tingyuan/react-native-tailwindcss/types" />

or import the types in a .d.ts file:

import "@tingyuan/react-native-tailwindcss/types"

or add the types in your tsconfig.json:

{ "types": [ "@tingyuan/react-native-tailwindcss/types"] }

Tailwind CSS IntelliSense

support tw() code hints and completion

"tailwindCSS.experimental.classRegex": [


  globals: { tw: 'readonly' },


If you encounter any problem, please try to restart your app without cache:

  • Expo npx expo start --clear
  • React Native CLI npx react-native start --reset-cache

The babel plugin will automatically inject const tw = useTw() in each react component function.

useTw is a hook callee, so using className or tw() must be in react component function.

When the function name is "UpperCamelCase" style and has jsx statement, the function self will be treated as a react component function.

So when you encounter error like Rendered fewer hooks than expected or Property 'tw' doesn't exist, you need to obey the limitation mentioned above.

If you see error like class xxx does not exist in generated tailwind styles, please make sure to run command mentioned above in No.3 (Start tailwindcss watch task for development.)

Limitation ⚠

I have to say, this project is not a comprehensive solution to use all features of tailwindcss in react-native(In fact, a considerable portion of the tailwindcss functionality is inherently exclusive to the web).

But it will cover the most useful features of tailwindcss, including most of utilities classes and some prefix modifiers such as dark mode, responsive break point, vw/vh unit, viewport orientation.

If you seek more enhanced and comprehensive solution, you can try NativeWind.

Package Sidebar


npm i @tingyuan/react-native-tailwindcss

Weekly Downloads






Unpacked Size

24.9 kB

Total Files


Last publish


  • tingyuan