일정 관리 상태 복원 - React StrictMode 이중 마운트 문제 해결

- useRef로 상태 복원 로직 한 번만 실행되도록 보장
- 두 번째 마운트에서 플래그/상태 삭제 방지
This commit is contained in:
caadiq 2026-01-06 12:22:10 +09:00
parent 2c766e8da6
commit 7df7469b78

View file

@ -20,9 +20,17 @@ function AdminSchedule() {
return kstDate.toISOString().split('T')[0]; return kstDate.toISOString().split('T')[0];
}; };
// sessionStorage // sessionStorage ( )
// (fromScheduleForm ) // (fromScheduleForm )
const stateRestoredRef = useRef(false);
const getStoredState = () => { const getStoredState = () => {
// (StrictMode )
if (stateRestoredRef.current) {
const stored = sessionStorage.getItem('adminScheduleState');
return stored ? JSON.parse(stored) : null;
}
stateRestoredRef.current = true;
try { try {
const fromForm = sessionStorage.getItem('fromScheduleForm'); const fromForm = sessionStorage.getItem('fromScheduleForm');
if (fromForm) { if (fromForm) {
@ -39,6 +47,7 @@ function AdminSchedule() {
const storedState = getStoredState(); const storedState = getStoredState();
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const [user, setUser] = useState(null); const [user, setUser] = useState(null);
const [toast, setToast] = useState(null); const [toast, setToast] = useState(null);
@ -517,7 +526,10 @@ function AdminSchedule() {
</div> </div>
<div className="flex items-center gap-3"> <div className="flex items-center gap-3">
<button <button
onClick={() => navigate('/admin/schedule/bots')} onClick={() => {
sessionStorage.setItem('fromScheduleForm', 'true');
navigate('/admin/schedule/bots');
}}
className="flex items-center gap-2 px-5 py-3 bg-gray-100 text-gray-700 rounded-xl hover:bg-gray-200 transition-colors font-medium" className="flex items-center gap-2 px-5 py-3 bg-gray-100 text-gray-700 rounded-xl hover:bg-gray-200 transition-colors font-medium"
> >
<Bot size={20} /> <Bot size={20} />