Devendra174's picture
Upload folder using huggingface_hub
f5071ca verified
raw
history blame contribute delete
980 Bytes
import { useEffect, useMemo, useState } from "react";
import { toast } from "react-hot-toast";
import { useSessionContext } from "@supabase/auth-helpers-react";
import { Song } from "@/types";
const useSongById = (id?: string) => {
const [isLoading, setIsLoading] = useState(false);
const [song, setSong] = useState<Song | undefined>(undefined);
const { supabaseClient } = useSessionContext();
useEffect(() => {
if (!id) {
return;
}
setIsLoading(true);
const fetchSong = async () => {
const { data, error } = await supabaseClient
.from('songs')
.select('*')
.eq('id', id)
.single();
if (error) {
setIsLoading(false);
return toast.error(error.message);
}
setSong(data as Song);
setIsLoading(false);
}
fetchSong();
}, [id, supabaseClient]);
return useMemo(() => ({
isLoading,
song
}), [isLoading, song]);
};
export default useSongById;