Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[question] How to define tailwind style outside a component? #175

Open
radiorz opened this issue Jun 14, 2022 · 3 comments
Open

[question] How to define tailwind style outside a component? #175

radiorz opened this issue Jun 14, 2022 · 3 comments

Comments

@radiorz
Copy link

radiorz commented Jun 14, 2022

the useTailwind must be in a component, but how could i define some styles outside the component function?

@frannale
Copy link

frannale commented Jun 14, 2022

I dont know what you want to do, but maybe you can pass the variable with the asignated useTailwind() as a parameter

@radiorz
Copy link
Author

radiorz commented Jun 15, 2022

Here is an example:

import React from 'react';
import {useTailwind} from 'tailwind-rn';
import {StyleSheet, TouchableOpacity, Text, Dimensions} from 'react-native';
export default function Card({title = '', cover = '?', isShow = false}) {
  const tailwind = useTailwind();
  return (
    <TouchableOpacity style={styles.button}>
      <Text style={[styles.buttonText, tailwind('text-2xl')]}>
        {isShow ? title : cover}
      </Text>
    </TouchableOpacity>
  );
}
const styles = StyleSheet.create({
  button: {
    backgroundColor: '#ccc',
    borderRadius: 8,
    width: 80,
    height: 80,
    justifyContent: 'center',
    alignItems: 'center',
    margin: (Dimensions.get('window').width - 100 * 4) / (4 * 2),
  },
  buttonText: {},
});

How could I write tailwind in stylesheet.create but not in component?

such as on web, we can use @apply to write tailwind in css styles

@alexisthual
Copy link

Did you find a solution to this? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants