Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6214

Using theme for styling in react native with typescript

$
0
0

I can use theme variable in makeStyles function and also I want to use theme variable in createStyles function

export type NamedStyles<T> = { [P in keyof T]: ViewStyle | TextStyle | ImageStyle }export const makeStyles = <T extends NamedStyles<T> | NamedStyles<any>>(  styles: (theme: Theme) => T) =>  <T extends NamedStyles<T> | NamedStyles<any>>() => {  const currentTheme = useTheme();  return styles(currentTheme);};const baseStyles = makeStyles((theme:Theme) => ({     // I can use here     container:{backgroundColor:theme.colors.primary}}))export const createStyles = <T extends NamedStyles<T> | NamedStyles<any>>(overrides : T | NamedStyles<T>) => {    return create({...baseStyles, ...overrides})  }//in component.tsx    const styles = createStyles({        // I want to use here as well    })

Viewing all articles
Browse latest Browse all 6214

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>