2
I’m building an application in React
and need to render a list of all users, called the API
. Use the map
to go through the users, but the browser returns the error:
TypeError: Cannot read property 'map' of undefined
.
My comfort is like this:
<ul>
{devs.map((dev) => (
<li key={dev._id} className="dev-item">
<header>
<img src={dev.avatar_url} alt={dev.name}></img>
<div className="user-info">
<strong>{dev.name}</strong>
<span>{dev.techs.join(', ')}</span>
</div>
</header>
<p>{dev.bio}</p>
<a href={`https://github.com/${dev.github_username}`}>Acessar perfil</a>
</li>
))}
</ul>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
How to resolve the error?
Where does that come from supposed array
devs
? In fact it is not an React error. Probablydevs
is not being accessed correctly-currently,devs
isundefined
, and therefore the mistake.– Luiz Felipe
You are doing the rocketseat week training and did not pay attention to the ball !!! kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
devs
and as it was maybe you initialized wrong. Well put the whole function.– novic