mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-03-20 12:11:28 -07:00
30 lines
784 B
TypeScript
30 lines
784 B
TypeScript
import { useState, useEffect } from 'react';
|
|
import { getStatsClient } from './useStatsApi';
|
|
import type { AnimeLibraryItem } from '../types/stats';
|
|
|
|
export function useAnimeLibrary() {
|
|
const [anime, setAnime] = useState<AnimeLibraryItem[]>([]);
|
|
const [loading, setLoading] = useState(true);
|
|
const [error, setError] = useState<string | null>(null);
|
|
|
|
useEffect(() => {
|
|
let cancelled = false;
|
|
getStatsClient()
|
|
.getAnimeLibrary()
|
|
.then((data) => {
|
|
if (!cancelled) setAnime(data);
|
|
})
|
|
.catch((err: Error) => {
|
|
if (!cancelled) setError(err.message);
|
|
})
|
|
.finally(() => {
|
|
if (!cancelled) setLoading(false);
|
|
});
|
|
return () => {
|
|
cancelled = true;
|
|
};
|
|
}, []);
|
|
|
|
return { anime, loading, error };
|
|
}
|