【问题标题】:Using Spotify API to Display User Top Artists使用 Spotify API 显示用户顶级艺术家
【发布时间】:2021-10-04 13:32:23
【问题描述】:
let topArtists;

spotify.getMyTopArtists().then((artists) => {
   topArtists = artists.items;
   console.log(topArtists);
}, (err) => {
   console.log('Error:', err);
});

return (
   <div className="test">
      <h1>{}</h1>
   </div>
);

我目前能够在控制台中显示用户的顶级艺术家,如上面的代码所示,但是,我想知道我需要在返回中添加什么才能在实际网页上显示顶级艺术家而不是在控制台中。

【问题讨论】:

    标签: reactjs spotify spotify-app


    【解决方案1】:

    使用状态来保存值,然后您可以映射您的状态以显示。 我已经包含了将艺术家添加到状态的代码。

    import React { useState } from "react";
    
    function App() {
     
      const [topArtists, setTopArtists] = useState([]);
    
    
      spotify.getMyTopArtists().then((artists) => {
         setTopArtists((prevEntries) => {
          return [artists.items, ...prevEntries];
        });
      }, (err) => {
        console.log('Error:', err);
    
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-11
      • 2015-01-30
      • 2015-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多