vadimdemedes/tailwind-rn

Tailwind RN not working - tailwind('text-3xl font-bold') returns {}

circles-png opened this issue · 4 comments

I can see tailwind.json being generated properly, but when I console.log(tailwind('text-3xl font-bold')); it returns an empty object.

My App.tsx:

import { Text, View } from 'react-native';
import { StatusBar } from 'expo-status-bar';
import utilities from './tailwind.json';
import { TailwindProvider, useTailwind } from 'tailwind-rn';
import React from 'react';

export default function App() {
  const tailwind = useTailwind();

  return (
    <TailwindProvider utilities={utilities}>
      <View>
        <Text style={tailwind('text-3xl font-bold')}>no</Text>
        <StatusBar style='auto' />
      </View>
    </TailwindProvider>
  );
}

Using Expo, using latest Tailwind RN.

A component using useTailwind needs to be below the <TailwindProvider>. Try something like this:

import { Text, View } from 'react-native';
import { StatusBar } from 'expo-status-bar';
import utilities from './tailwind.json';
import { TailwindProvider, useTailwind } from 'tailwind-rn';
import React from 'react';

export default function App() {
 
  return (
    <TailwindProvider utilities={utilities}>
      <SomePage />
    </TailwindProvider>
  );
}

function SomePage() {
  const tailwind = useTailwind();

  return (
    <View>
      <Text style={tailwind('text-3xl font-bold')}>no</Text>
      <StatusBar style='auto' />
    </View>
  )
}

Share your tailwind.config.js file, if possible.
Or try to set the content option in tailwind.config.js and run the command npm run dev:tailwind or yarn dev:tailwind to watch for changes.

Don't forget to set where Tailwind CSS should be looking for classes. See content of tailwind.config.js in Tailwind CSS docs.

groom7 commented

Используемый компонент useTailwindдолжен быть ниже <TailwindProvider>. Попробуйте что-то вроде этого:

It helped me. Thank you!
Just in case, I’ll leave tags for other people, because I myself didn’t find this solution the first time:
tailwind-rn return empty object