import { useSpotify } from './hooks/useSpotify';
import { Scopes, SearchResults, SpotifyApi } from '../../src';
import { useEffect, useState } from 'react'
import './App.css'
function App() {
const sdk = useSpotify(
import.meta.env.VITE_SPOTIFY_CLIENT_ID,
import.meta.env.VITE_REDIRECT_TARGET,
Scopes.userDetails
);
return sdk
? ()
: (<>>);
}
function SpotifySearch({ sdk }: { sdk: SpotifyApi}) {
const [results, setResults] = useState>({} as SearchResults<["artist"]>);
useEffect(() => {
(async () => {
const results = await sdk.search("The Beatles", ["artist"]);
setResults(() => results);
})();
}, [sdk]);
// generate a table for the results
const tableRows = results.artists?.items.map((artist) => {
return (
| {artist.name} |
{artist.popularity} |
{artist.followers.total} |
);
});
return (
<>
Spotify Search for The Beatles
| Name |
Popularity |
Followers |
{tableRows}
>
)
}
export default App;