Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

115
Vistas
Data from React Hook not updating UI from state

I'm struggling to see what is wrong with my code here, but essentially the function from the useSongInfo hook is working, however it isn't updating the player UI.

I've attached both components below. Whenever I click a new song, I can see the new data coming through in the console.log(songInfo?.name), however it is not showing he dynamic image or dynamic text component data inside the Box.

Does anyone have any idea what is happening? I've also tried using Context to store the songInfo globally, however still get the same issue.

const Player = () => {
    const songInfo = useSongInfo()
    console.log(songInfo?.name, "song info from player");

  return (
    <Box
      position={"fixed"}
      bottom={0}
      left={0}
      right={0}
      bg={"gray.100"}
      height={"80px"}
    >
      <Box position={"relative"} w={12} h={12}>
        {songInfo?.album.images[1]?.url ? (
          <Image src={songInfo?.album.images[1]?.url} layout={"fill"} />
        ) : (
          <Box />
        )}
        <Text>{songInfo?.name} TEST</Text>
      </Box>
    </Box>
  );
};


function useSongInfo() {
  const currentTrackId = "123"
  const spotifyAccessToken = "dummy-access-token"

  const [songInfo, setSongInfo] = useState<SpotifySong>();

  useEffect(() => {
    const fetchSongInfo = async () => {
      if (currentTrackId && spotifyAccessToken) {
        const trackInfo = await fetch(
          `https://api.spotify.com/v1/tracks/${currentTrackId}`,
          {
            headers: {
              Authorization: `Bearer ${spotifyAccessToken}`,
            },
          }
        ).then((res) => res.json());
        setSongInfo(trackInfo);
      }
    };
    fetchSongInfo();
  }, [currentTrackId, spotifyAccessToken]);

  return songInfo;
}

To show that values change on click, here are values from both songInfo?.name and songInfo?.album.images1?.url enter image description here

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda