Files
JKVideo/hooks/useRelatedVideos.ts

27 lines
786 B
TypeScript
Raw Normal View History

import { useState, useCallback, useRef } from 'react';
import { getVideoRelated } from '../services/bilibili';
2026-03-19 16:34:56 +08:00
import type { VideoItem } from '../services/types';
export function useRelatedVideos(bvid: string) {
const [videos, setVideos] = useState<VideoItem[]>([]);
2026-03-19 16:34:56 +08:00
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);
2026-03-19 16:34:56 +08:00
} catch (e) {
console.warn('useRelatedVideos: failed', e);
} finally {
loadingRef.current = false;
setLoading(false);
}
}, [bvid]);
2026-03-19 16:34:56 +08:00
return { videos, loading, load, hasMore: false };
2026-03-19 16:34:56 +08:00
}