Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

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

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

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Not sure to really understand what you are trying to do. For What I understood, you have a prop and you try to define a certain fontSize when prop is true and another one when it's not.

I would do :

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

Or if your "textListStyle?.fontSize" is an integer:

style={{fontSize: textListStyle?.fontSize ?? 15}}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!