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

122
Vistas
React Native Conditional Mapping Return

I have an array, splitByDay:

Array [
  Object {
    "Day": "Sunday",
    "data": "Upper",
  },
  Object {
    "Day": "Monday",
    "data": "Lower",
  },
]

and a function:

const getDay = (it) => {

          splitByDay.map((x, i) => {
            let day = x["Day"];
              if (day === it){

              return x["data"]
              } else { return "Rest" }
            
          })
      }

inside a FlatList, I pass in it which is the current day.

My goal is to return the corresponding piece of data if the day aligns. Here is the how its called:

 <Text style={[tailwind(`text-gray-300 font-[400px] text-[11px]`), {color: item === currentDay ? colors.purple : 'white'}]}>{getDay(item)}</Text>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The problem is that you try to filter and map the data at once inside the map function. You should split that up, first filter the data and then map the data you want.

For example this code:

  const getDay = (it) => {
    return splitByDay.filter((x)=> x["Day"] === it).map((x) => x["Data"])[0]
  }
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