Back

Technologies:

javascriptjavascript
htmlhtml
reactjsreactjs
avatar
Tolerim
4 hours ago

How can I transfer the playlist tracks from the Playlist component to the TrackList component?

I am currently facing an issue with passing playlist tracks from the Playlist component to the TrackList component in my project. Despite carefully examining my code, I am unable to find a solution. To give you a better idea of what's going on, here's a link to my webpage: http://localhost:3000/web page. As you can see, the webpage is supposed to look like this: , with the information from the results replicated in the new playlist section as well. The TrackList component is visible when imported to the Results component but not when imported to the Playlist (New Playlist) component on the right-hand side of the webpage. For your reference, here's the code for the Results and Playlist components as well as the TrackList component: Results Component:

import React from 'react';
import './SearchResults.css';
import TrackList from '../../TrackList/TrackList';

class SearchResults extends React.Component {
   render () {
    return (
        
        

Results

) } } export default SearchResults;
Playlist Component:

import React from 'react';
import './Playlist.css';
import TrackList from '../TrackList/TrackList';

class Playlist extends React.Component {
    render() {
       return (
        
        
         
        

       ) 
    }
}
export default Playlist;
TrackList Component:

import React from "react";
import './TrackList.css';
import Track from "../Track/Track";

class TrackList extends React.Component {
    render() {
      return (
          
            {      
            this.props.tracks?.map(track => {
              return ;
            })
        } 

      ) 
    }
}
export default TrackList;
Any help or guidance would be highly appreciated.
Answers(1)
avatar
Tolerim
4 hours ago
Verified Answer
It looks like you're having trouble passing the playlist tracks from the Playlist component to the TrackList component. In the Playlist component, you're passing this.props.playlistTracks to the TrackList component as a prop, but I don't see where you're actually setting the value of this.props.playlistTracks. Assuming you're trying to pass the playlist tracks from the App component down to the Playlist component, you should pass it down as a prop when rendering the Playlist component in the App component. For example:
This assumes that you're storing the playlist tracks in the state of the App component and passing them down to the Playlist component as a prop. Once you've passed the playlist tracks down to the Playlist component, it should be able to pass them down to the TrackList component as a prop just like in the SearchResults component. Hope this helps! Let me know if you have any other questions.
;