Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit56dba6f

Browse files
authored
Retaining the modified title on component unmount made optional. (#2)
* Option added to retain the modified title or to rollback to the default title ON the corresponding component unmount event (e.g. route change -> title change for those using this hook, but rollback to the default/original title for those routes not using this hook.)* Using useRef to get the default title.
1 parent3f1e3db commit56dba6f

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

‎index.js‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
'use strict';
2-
let{ useEffect}=require('react');
2+
let{ useRef, useEffect}=require('react');
3+
4+
functionuseDocumentTitle(title,retainOnUnmount=false){
5+
constdefaultTitle=useRef(document.title);
36

4-
functionuseDocumentTitle(title){
57
useEffect(()=>{
68
document.title=title;
7-
},[title])
9+
10+
return()=>{
11+
if(!retainOnUnmount)document.title=defaultTitle.current;
12+
};
13+
},[title]);
814
}
915

1016
module.exports=useDocumentTitle;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp