it turns out that I'm having a small problem that I find very strange that is not solved with the OR operator (||).
In the following code, you can see that I am sending a
return (
<div>
{listShow.map(i => (
<Link to={`/noticias/detalle/${i.categoria.id/${i.id}`} key={i.id}>
<h3>{i.titulo}</h3>
<img
alt={i.titulo}
src={process.env.REACT_APP_IMG_BASE + i.imagen_intro}
width={500}
/>
</Link>
))}
);
However, at some point, "i.categoria.id" becomes null and this generates an error that says:
"TypeError: Can not read property 'id' of null"
Then, I tried this:
return (
<div>
{listShow.map(i => (
<Link to={`/noticias/detalle/${i.categoria.id/${i.id} || 'WithoutCat'`} key={i.id}>
<h3>{i.titulo}</h3>
<img
alt={i.titulo}
src={process.env.REACT_APP_IMG_BASE + i.imagen_intro}
width={500}
/>
</Link>
))}
);
I would like to know how to solve this, since it seems strange to me that I take the value when I am putting the operator ||
Thank you!
categoria.idis undefined and you set "WithoutCat" as a fallback, you might end up with dead links.