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

205
Visualizações
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 à 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