diff --git a/src/useTitle.ts b/src/useTitle.ts index e1f32cdce5..0ce2f35c5d 100644 --- a/src/useTitle.ts +++ b/src/useTitle.ts @@ -14,14 +14,15 @@ function useTitle(title: string, options: UseTitleOptions = DEFAULT_USE_TITLE_OP if (document.title !== title) document.title = title; useEffect(() => { + const curTitleRef = prevTitleRef.current; if (options && options.restoreOnUnmount) { return () => { - document.title = prevTitleRef.current; + document.title = curTitleRef; }; } else { return; } - }, []); + }, [options]); } export default typeof document !== 'undefined' ? useTitle : (_title: string) => {};