Home > front end >  how to use tailwind imports with react native- can tailwind be shortened to tw?
how to use tailwind imports with react native- can tailwind be shortened to tw?

Time:07-01

I am following this youtube tutorial https://www.youtube.com/watch?v=qJaFIGjyRms at the 20 minute mark he imports tailwind as tw then proceeds to use it in app.js I have done the exact same thing yet I am getting the error "TypeError: (0, _tailwindRn.tw) is not a function. (In '(0, _tailwindRn.tw)("justify-center items-center")', '(0, _tailwindRn.tw)' is undefined)"

screenshot

my code:

    import { StatusBar } from 'expo-status-bar';
    import { StyleSheet, Text, View } from 'react-native';
    import {tw} from 'tailwind-rn';

    export default function App() {
      return (
        <View style={tw("justify-center items-center")}>
          <Text>Open up App.js to start working on your             app!</Text>
          <StatusBar style="auto" />
        </View>
      );
    }

    const styles = StyleSheet.create({
      container: {
        flex: 1,
        backgroundColor: '#fff',
        alignItems: 'center',
        justifyContent: 'center',
      },
    });

CodePudding user response:

You need to install the tailwind-rn npm package.

More info https://www.npmjs.com/package/tailwind-rn

CodePudding user response:

If you go back and look at the tutorial, they are using

import tw from 'tailwind-rn';

not

import {tw} from 'tailwind-rn';

You can name the default export of a library whatever you like in the import statement.

import TailWind from 'tailwind-rn'; import t from 'tailwind-rn'; etc.

  • Related