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

How to change font base on props and set default if there is no prop

$
0
0

The question is pretty simple, i have a text, which have a default prop, fontSize, problem is i want to have props to change that size when needed, so i set default font and a props to change font, but i really don't know what is the right way to do this.

Here is my did'nt work solution:

The props called textStyle, i define by using typescript interface textStyle: TextStyle

I tried to have conditions in style like

style={textListStyle?.fontSize ?? 15}   <== not work

The complier complain

No overload matches this call.  Overload 1 of 2, '(props: TextProps | Readonly<TextProps>): Text', gave the following error.    Type 'number' is not assignable to type 'StyleProp<TextStyle>'.  Overload 2 of 2, '(props: TextProps, context: any): Text', gave the following

error.

And i tried

style={!textListStyle?.fontSize ? 15 : textListStyle?.fontSize}

Same issue, so what is the best solution?Thank you so much


Viewing all articles
Browse latest Browse all 6287

Trending Articles



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