Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

96
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda