Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

245
Visualizações
Component's prop value isn't showing in React.js

I'm trying to make a clone of Spotify where I'm using Spotify-web-API to access all the user data (id, name, playlist info, etc.) And to avoid prop drilling all these data are getting stored in Datalayer with the help of React-Context-api. I have a component Sidebar.js where all the playlist names are getting pulled from the API and will be shown in the sidebar. Inside this component, I also have another component SidebarOption.js to show names of playlists. Although I'm getting the playlist names from the API but when I passed those in the SidebarOption.js component as title prop it isn't showing there. I also console logged the names to be sure. The names are showing in my console but not through the mapping function in SidebarOption component. I've attached a screenshot of what I'm getting in this link Screenshot of console log.

You'll see that outside the mapping function any prop value passed in the SidebarOption component is showing but not the ones inside the mapping function. So any help would be appreciated.

Sidebar.js

function SideBar() {
  const [{ playlists }, dispatch] = UseDataLayerValue();
  console.log("user playlist from sidebar.js", playlists);

  return (
    <div className="sidebar">
      <img
        className="sidebar__logo"
        src="https://getheavy.com/wp-content/uploads/2019/12/spotify2019-830x350.jpg"
        alt="spotify-logo"
      />
      <SidebarOption Icon={HomeIcon} title="Home" />
      <SidebarOption Icon={SearchIcon} title="Search" />
      <SidebarOption Icon={LibraryMusicIcon} title="Your Library" />
      <br />
      <strong className="sidebar__title">PLAYLISTS</strong>
      <hr />

      {playlists?.items?.map((playlist) => {
        console.log(playlist.name);
        <h2>hi</h2>;
        <SidebarOption title={playlist.name} />;
      })}
    </div>
  );
}

SidebarOption.js

function SidebarOption({ title, Icon }) {
  return (
    <div className="sidebarOption">
      {Icon && <Icon className="sidebarOption__icon" />}
      {Icon ? <h4>{title}</h4> : <p>{title}</p>}
    </div>
  );
}
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

The main problem is, you're using a map. But, you're not returning the value.

You have:

 {playlists?.items?.map((playlist) => {
        console.log(playlist.name);
        <h2>hi</h2>;
        <SidebarOption title={playlist.name} />;
      })}

Should be:

{playlists?.items?.map((playlist) => {
  console.log(playlist.name);
  <h2>hi</h2>;
  return <SidebarOption title={playlist.name} />;
})}

Here is the Codesandbox to notice: https://codesandbox.io/s/wizardly-sun-iku99?file=/src/App.js

about 4 years ago · Juan Pablo Isaza Relatório

0

the problem here is that you are not returning the SidebarOption in the map function you instead can do it like that

{playlists?.items?.map((playlist) => {
        console.log(playlist.name);
        return (
          <>
            <h2>hi</h2>;
            <SidebarOption title={playlist.name} />;
          </>
        );
      })}

or

  {playlists?.items?.map((playlist) => (
        <>
          <h2>hi</h2>;
          <SidebarOption title={playlist.name} />;
        </>
      ))}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda