feat(saju): 사주풀이 5 컴포넌트 + useSajuReading hook

This commit is contained in:
2026-05-26 08:31:10 +09:00
parent 2dd92d025f
commit 36665ec308
6 changed files with 176 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
import { useState, useEffect } from 'react';
import { sajuGetReading } from '../../../api';
export default function useSajuReading(readingId) {
const [data, setData] = useState(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);
useEffect(() => {
if (!readingId) {
setLoading(false);
return;
}
let cancelled = false;
setLoading(true);
sajuGetReading(readingId)
.then((d) => {
if (!cancelled) {
setData(d);
setLoading(false);
}
})
.catch((e) => {
if (!cancelled) {
setError(e.message || '사주 결과를 불러올 수 없습니다.');
setLoading(false);
}
});
return () => { cancelled = true; };
}, [readingId]);
return { data, loading, error };
}