Hey everyone. I am having issues with step 34 of the Jammming project. I keep on getting the following error: Cannot read properties of undefined (reading ‘map’)
TypeError: Cannot read properties of undefined (reading ‘map’).
I have tried everything, read multiple forums with many different solutions but no luck. Here is my Tracklist code with the map function method:
import React from “react”;
import styles from “./Tracklist.module.css”;
import Track from “../Track/Track”;
function Tracklist(props) {
return (
{/* */}
{props.userSearchResults.map((track) => {
<Track track={track} key={track.id}/>
})}
);
}
export default Tracklist;
Here is my SearchResult component:
import React from “react”;
import styles from “./SearchResults.module.css”;
import Tracklist from “../Tracklist/Tracklist”;
function SearchResults (props) {
return (
{/* */}
);
}
export default SearchResults;
And finally, here is my App component:
import React, { useState } from “react”;
import styles from “./App.module.css”;
import SearchResults from “../SearchResults/SearchResults”;
import Playlist from “../Playlist/Playlist”;
function App () {
const [searchResults, setSearchResults] = useState([{
name: “example track name 1”,
artist: “example track artist 1”,
album: “example track album 1”,
id: 1
}, {
name: “example track name 2”,
artist: “example track artist 2”,
album: “example track album 2”,
id: 2
} ]);
const [playlistName, setPlaylistName] = useState(“Example Playlist”);
const [playlistTracks, setPlaylistTracks] = useState([{
name: “example track name 1”,
artist: “example track artist 1”,
album: “example track album 1”,
id: 1
}, {
name: “example track name 2”,
artist: “example track artist 2”,
album: “example track album 2”,
id: 2
}]);
return (
<div>
<h1>
Ja<span className={styles.highlight}>mmm</span>ing
</h1>
<div className={styles.App}>
{/* <!-- Add a SearchBar component --> */}
<div className={styles["App-playlist"]}>
{/* <!-- Add a SearchResults component --> */}
<SearchResults userSearchResult={searchResults}/>
{/* <!-- Add a Playlist component --> */}
<Playlist playlistName={playlistName} playlistTracks={playlistTracks}/>
</div>
</div>
</div>
);
}
export default App;
I believe that the error is coming from the Tracklist component where the map function is not getting the data from the props. I’ve tried everything to get the data from App to the Tracklist but have been unable to figure it out. I’ve been stuck on this for over a day and can’t figure it out. Any help would be greatly appreciated.