Spaces:
Running
Running
Download frontend/src/hooks/useTestLoader.js from banu4prasad/Gateprep: direct link, hf CLI and curl.
- Browser
- Download file 808 Bytes
-
https://huggingface.co/spaces/banu4prasad/Gateprep/resolve/main/frontend/src/hooks/useTestLoader.js
- Command line
-
hf download hf://spaces/banu4prasad/Gateprep/frontend/src/hooks/useTestLoader.js
-
curl -L -o useTestLoader.js https://huggingface.co/spaces/banu4prasad/Gateprep/resolve/main/frontend/src/hooks/useTestLoader.js
808 Bytes
| import { useEffect, useState } from 'react' | |
| import toast from 'react-hot-toast' | |
| import { testAPI } from '../api/api' | |
| export default function useTestLoader({ testId, navigate }) { | |
| const [test, setTest] = useState(null) | |
| const [loading, setLoading] = useState(true) | |
| useEffect(() => { | |
| let cancelled = false | |
| ;(async () => { | |
| setLoading(true) | |
| setTest(null) | |
| try { | |
| const testRes = await testAPI.getTest(testId) | |
| if (cancelled) return | |
| setTest(testRes.data) | |
| } catch (err) { | |
| toast.error(err.response?.data?.detail || 'Failed to load test') | |
| navigate('/tests') | |
| } finally { | |
| if (!cancelled) setLoading(false) | |
| } | |
| })() | |
| return () => { | |
| cancelled = true | |
| } | |
| }, [testId, navigate]) | |
| return { test, loading } | |
| } |