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

282
Vistas
react native : What is the way to create an enum with 3 color types?

In my example I try add a variable button_gradient_color with 3 parameters of color and it shows an error. The error is: Enum member must have initializer

What is the way to create an enum with 3 color types ?

export enum Colors {
 background_color = '#000060',
 button_gradient_color = '#4c669f', '#3b5998', '#192f6a'
};

this is the LinearGradient

<LinearGradient
            colors={ Colors.button_gradient_color1,Colors.button_gradient_color2,Colors.button_gradient_color3}

 >
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Currently one variable initialized to multiple values is not allowed. You can either separate the color gradients into 3 different variables like below, if that helps you in your situation.

export enum Colors {
 background_color = '#000060',
 button_gradient_color1 = '#4c669f', 
 button_gradient_color2 = '#3b5998',
 button_gradient_color3 =  '#192f6a'
};

Playground

And you could refer like Colors.button_gradient_color1 perhaps.

While passing it to the LinearGradient component you can do is:

<LinearGradient colors={[ Colors.button_gradient_color1, Colors.button_gradient_color2  Colors.button_gradient_color3 ]} >
about 4 years ago · Juan Pablo Isaza Denunciar

0

You can do it like this since the enum has already been declared

  <LinearGradient
    Colors={[
      Colors.button_gradient_color1, 
      Colors.button_gradient_color2,
      Colors.button_gradient_color3
    ]}
  >
about 4 years ago · Juan Pablo Isaza Denunciar
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