Files
JKVideo/hooks/useRelatedVideos.ts
Developer 3f82646496 init
2026-03-26 12:15:40 +08:00

27 lines
781 B
TypeScript

import { useState, useCallback, useRef } from 'react';
import { getVideoRelated } from '../services/api';
import type { VideoItem } from '../services/types';
export function useRelatedVideos(bvid: string) {
const [videos, setVideos] = useState<VideoItem[]>([]);
const [loading, setLoading] = useState(false);
const loadingRef = useRef(false);
const load = useCallback(async () => {
if (loadingRef.current) return;
loadingRef.current = true;
setLoading(true);
try {
const data = await getVideoRelated(bvid);
setVideos(data);
} catch (e) {
console.warn('useRelatedVideos: failed', e);
} finally {
loadingRef.current = false;
setLoading(false);
}
}, [bvid]);
return { videos, loading, load, hasMore: false };
}