Skip to content

Basic Usage

Basic Usage

Requirements

After the initial setup, you only need to focus on two functions responsible for your styles:

  • createStyleSheet which replaces StyleSheet.create
  • useStyles which parses your styles and ensures TypeScript compatibility with media queries and breakpoints
import React from 'react'
import { View, Text } from 'react-native'
// access createStyleSheet and useStyles exported from factory
import { createStyleSheet, useStyles } from 'lib/styles'

export const ExampleUnistyles = () => {
    const { styles } = useStyles(stylesheet)

    return (
        <View style={styles.container}>
            <Text style={styles.text}>
                Unistyles example
            </Text>
        </View>
    )
}

const stylesheet = createStyleSheet(theme => ({
    container: {
       flex: 1,
       justifyContent: 'center',
       alignItems: 'center',
       backgroundColor: theme.colors.background
    },
    text: {
       color: theme.colors.typography
    }
}))