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:
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.
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...