diff --git a/frontend/src/b/region.tsx b/frontend/src/b/region.tsx index 91f3e8c..6361805 100644 --- a/frontend/src/b/region.tsx +++ b/frontend/src/b/region.tsx @@ -76,6 +76,11 @@ export function RegionProvider({ children }: { children: ReactNode }) { codeRef.current = region.code }, [region.code]) const followedAt = useRef(0) + // navigate 는 화면을 옮길 때마다 새 함수가 된다. 그대로 save 에 넣으면 save 와 그걸 쓰는 위치 맞춤 effect 가 탭을 옮길 때마다 다시 돌아, 목록에서 고른 지역이 지금 위치로 되돌아간다 + const navigateRef = useRef(navigate) + useEffect(() => { + navigateRef.current = navigate + }, [navigate]) // 지역 페이지에서 고르면 주소도 그 지역 페이지로 바꿔, 공유한 링크가 보던 화면과 같게 한다 const save = useCallback((r: RegionData, by: By) => { @@ -83,8 +88,8 @@ export function RegionProvider({ children }: { children: ReactNode }) { writeStored(r, by) byRef.current = by const next = ownPage(r.code) - if (pageRef.current && next && next !== pageRef.current) navigate(`/${dayRef.current}/${next.path}`) - }, [navigate]) + if (pageRef.current && next && next !== pageRef.current) navigateRef.current(`/${dayRef.current}/${next.path}`) + }, []) const setRegion = useCallback((r: RegionData) => save(r, 'list'), [save])