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

101
Visualizações
Operator that adds the correct spread to <label> attribute

I have two functions that both set different values. In the markup, how do I set the attribute to have the correct spread. I know how to do this with the standard ternary operator but I don't want to copy the same code for everything that goes under the attribute, as it's wrapped inside of it.

  const labelAttributes = ['checkbox'].includes(type)
    ? keyboardEvents({ space: () => helpers.setValue(!field.value) })
    : null;

  const labelAttributesRadio = ['radio'].includes(type)
    ? keyboardEvents({ space: () => helpers.setValue(value) })
    : null;

return (
        {type == 'radio' ? (
          <label {...labelAttributesRadio}>
        ) : (
          <label {...labelAttributes}>
        )}
          // Removed a lot more content but don't want to have to copy it twice within the operator
          <Field>
          </Field>
          <span>
          </span>
        </label>

)

about 4 years ago · Juan Pablo Isaza
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