For now everything is static data .
I have a parent sate: an array containing 4 objects like so :
function App(){
const [searchResults,setSearchResults] =
useState([
{
name: 'name1',
artist: 'artist1',
album: 'album1',
id: 1
},
{
name: 'name2',
artist: 'artist2',
album: 'album2',
id: 2
},
{
name: 'name3',
artist: 'artist3',
album: 'album3',
id: 3
},
{
name: 'name4',
artist: 'artist4',
album: 'album4',
id: 4
}
]);
i pass this state to the child in the return with this it works as expected :
return (
<SearchResults searchResults = {searchResults} />
)
and from i pass it to :
import React,{useEffect,useState} from "react";
import './SearchResults.css';
import TrackList from '../TrackList/TrackList';
export default function SearchResults({searchResults}) {
return (
<div className="SearchResults">
<h2>Results</h2>
<TrackList tracks = {searchResults} />
</div>
)
}
now is where things got me confused.
i try to map the data from the array to the child of this component like this(this is the whole component) :
import React,{useEffect,useState} from "react";
import './TrackList.css';
import Track from '../Track/Track'
export default function TrackList(props) {
return(
<div className="TrackList">
{
props.tracks.map( track => {
<Track track = {track} key = {track.id} />
})
}
</div>
)
}
and i get this error with the local server displaying a white screen [1]: https://i.stack.imgur.com/5niRQ.png
- i tried destructuring and assigning props value to a variable before mapping but didn't work .
- also when i remove the .map i can see that has a props with expected data in it using react dev tools .