Parcourir la source

fix: infinite loop when artists response is undefined

Fela Maslen il y a 5 ans
Parent
commit
6645efa680
1 fichiers modifiés avec 3 ajouts et 1 suppressions
  1. 3 1
      gmus-web/src/hooks/fetch/artists.ts

+ 3 - 1
gmus-web/src/hooks/fetch/artists.ts

@@ -9,6 +9,8 @@ type ArtistsResponse = {
   artists: string[];
 };
 
+const emptyArtists: string[] = [];
+
 export function useArtists(): ArtistsResponse & {
   fetching: boolean;
 } {
@@ -24,7 +26,7 @@ export function useArtists(): ArtistsResponse & {
 
   useEffect(onFetch, [onFetch]);
 
-  return { artists: response?.artists ?? [], fetching };
+  return { artists: response?.artists ?? emptyArtists, fetching };
 }
 
 type ArtistDependencyResponse<K extends string, T> = { artist: string } & { [key in K]: T[] };