Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

151
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda