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

131
Visualizações
RTK query is looping over result but not providing the expected content

I'm currently doing the Redux Essentials tutorial and stuck in chapter 7: When switching from the classical thunk to the RTK query, the mapping will not work:

content = posts.map(post => <PostExcerpt key={post.id} post={post} />)

The error message is:

Unhandled Rejection (TypeError): Cannot read properties of undefined (reading 'title')

To find the reason, I've broken the code down to something simple as follows:

} else if (isSuccess) {
    content = '';
    //content = posts.map(post => <PostExcerpt key={post.id} postId={post}/>);
    if (posts !== undefined) {
        for (const post1 in posts)
            if (post1 !== undefined) content +=
                ' loop: ' + post1.toString() + ' typ: ' + typeof(post1) + ' ID: ' + post1.title + '!!';
            else content += 'kein post';
    }

The output of my curious code is:

loop: 0 typ: string ID: undefined!! loop: 1 typ: string ID: undefined!! loop: 2 typ: string ID: undefined!!

So it is looping but not having the right values in the variable. This is weird as the posts variable seems to have the right content. Here is the output of the evaluation:

Evaluation of "posts" variable

Opening the Sandbox at the end of the mentioned tutorial page also does not render the posts - so there might be a bug somewhere.

As I didn't find any similar problem description, I hope, you may give me a hint of what is wrong.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It is running now without problem. To be honest, I unfortunately do not know, why. Can't find any difference in my code history, which might allow to recognize, what happend. Bizarre...

about 4 years ago · Juan Pablo Isaza Relatório
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