ddewzy
1
i built this app through the tutorial and im getting this error
×
TypeError: Cannot read property ‘map’ of undefined
App
src/components/App.js:87
84 | {loading && !errorMessage ? ( 85 | <span>loading... </span> 86 | ) : errorMessage ? (> 87 | <div className="errorMessage">{errorMessage}</div> | ^ 88 | ) : ( 89 | movies.map((movie, index) => ( 90 | <Movie key={`${index}-${movie.Title}`} movie={movie} />
please help
This isn’t enough information to accurately assess the problem - but the error is clear enough. movies
is undefined when you try to .map
over it.
This usually means that you are trying to use it before it’s been populated with data.
You may be able to fix this with movies && movies.map(...)
, or movies?.map(...)
if you’re able to use optional chaining in your code base.
These act as a shorthand for “If movies has data in it, then map over movies to render the things”.
ddewzy
3
Yes adding the ? to movies worked thank you very much:)