feat(lotto): useReview 훅 + useBriefing 4계층 정규화
This commit is contained in:
23
src/pages/lotto/hooks/useReview.js
Normal file
23
src/pages/lotto/hooks/useReview.js
Normal file
@@ -0,0 +1,23 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { getLatestReview, getReviewHistory } from '../../../api';
|
||||
|
||||
export default function useReview() {
|
||||
const [latest, setLatest] = useState(null);
|
||||
const [history, setHistory] = useState([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
let cancel = false;
|
||||
Promise.all([getLatestReview(), getReviewHistory(4)])
|
||||
.then(([l, h]) => {
|
||||
if (cancel) return;
|
||||
setLatest(l);
|
||||
setHistory(h);
|
||||
})
|
||||
.catch(() => {})
|
||||
.finally(() => !cancel && setLoading(false));
|
||||
return () => { cancel = true; };
|
||||
}, []);
|
||||
|
||||
return { latest, history, loading };
|
||||
}
|
||||
Reference in New Issue
Block a user