MCPcopy Create free account
hub / github.com/Abhinav1416/coding-platform / useProblem

Function useProblem

frontend/src/features/problem/hooks/useProblem.ts:5–30  ·  view source on GitHub ↗
(slug: string)

Source from the content-addressed store, hash-verified

3import type { ProblemDetail } from '../types/problem';
4
5export const useProblem = (slug: string) => {
6 const [problem, setProblem] = useState<ProblemDetail | null>(null);
7 const [isLoading, setIsLoading] = useState<boolean>(true);
8 const [error, setError] = useState<string | null>(null);
9
10 useEffect(() => {
11 const fetchProblem = async () => {
12 try {
13 setIsLoading(true);
14 setError(null);
15 const data = await getProblemBySlug(slug);
16 setProblem(data);
17 } catch (err: any) {
18 setError(err.message || 'Failed to fetch problem details.');
19 } finally {
20 setIsLoading(false);
21 }
22 };
23
24 if (slug) {
25 fetchProblem();
26 }
27 }, [slug]);
28
29 return { problem, isLoading, error };
30};

Callers 1

ProblemPageFunction · 0.90

Calls 1

fetchProblemFunction · 0.85

Tested by

no test coverage detected