From 8e58fb695786a9e7944345fd670499791df30846 Mon Sep 17 00:00:00 2001 From: gtoxlili <664037691@qq.com> Date: Sun, 7 Apr 2024 19:06:29 +0800 Subject: [PATCH] fix: Restore original document title on component unmount in useDocumentTitle hook --- index.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/index.js b/index.js index f6e4fe2..1c75037 100644 --- a/index.js +++ b/index.js @@ -263,8 +263,13 @@ export function useDefault(initialValue, defaultValue) { } export function useDocumentTitle(title) { + const initial = React.useRef(document.title); + React.useEffect(() => { document.title = title; + return () => { + document.title = initial.current; + } }, [title]); }