score:3

const Player = () => {
  const { songs } = useContext(SongContext);
  const [currentSong, setCurrentSong] = useState(0);

  const song = songs[currentSong];
  
  if(!song) return null; // don't render the player when no song is available

  return (
    <div className="player">
      <AudioPlayer
        autoPlay
        src={song.preview}
        showJumpControls={false}
        customVolumeControls={[]}
        customAdditionalControls={[]}
        onPlay={() => console.log('playing')}
        onEnded={() => setCurrentSong(i => i + 1)}
      />
    </div>
  );
};

Related Query

More Query from same tag