This error is telling you that the clients
object which you are selecting from redux is undefined
. It might be that it starts out as undefined
and then populates with the data asynchronously, so it would be undefined
on the first render but fine afterwards. If it is continuing to stay undefined
then there is an issue somewhere else in your code.
There are two easy ways to deal with data that might not exist yet.
- You can replace
undefined
with an empty array and render the rest of the component normally. You would have a list with no items and 0 balance.
const clients = useSelector((state) => state.firestore.ordered.client) || [];
- You can stop the rest of the component from rendering. Either render nothing or a render some loading screen.
const clients = useSelector((state) => state.firestore.ordered.client);
if ( ! clients ) {
return (<div>Loading...</div>);
}
// the rest of the component continues below
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…