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

200
Vistas
How to catch correct value in conditional in React.js?
const [
  MessageListDataProvider,
  useMessageListData
] = constate(() => {
  const [newValue, setNewValue] = useState({})

  const [messagePath, useMessagePath] = useState(api.UNRESOLVED_MESSAGES_PATH)
  const getMessagePath = (newPath) => {
    useMessagePath(newPath)
  }
  const {
    value,
    loading,
    error,
    retry: refresh
  } = useAsyncRetry(async () => {
    return api.fetchAllMessages(messagePath)
  }, [messagePath])

   if (value !== undefined) {
    console.log('value.messages', value.messages.length)
    if (!newValue[messagePath]) {
      console.log('newValue in conditional', newValue)
      setNewValue(oldObj => ({ ...newValue, [messagePath] : value.messages }))
    } 
  }
  console.log('newValue', newValue)
  return {
    newValue,
    getMessagePath,
    value,
    loading,
    error,
    refresh
  }
})

I am trying to store specific values from an API call in a separate object based different keys.

example:

newValue : {
    `/messages?limit=100&offset=0`: [{}, {}, {}],
    `/messages?status=Unresolved&limit=100&offset=0`: [{}, {}, {}, {}, {}],
}

Strangely, the key gets updated and added but not the array value???!

See below...

enter image description here

Any idea how I can—for a lack of a better idea "catch" that API array value?

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