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

Retaining the modified title on component unmount made optional.#2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
iamsolankiamit merged 2 commits intorehooks:masterfromkckusal:retaining-modified-title-made-optional
Apr 23, 2020
Merged
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
NextNext commit
Option added to retain the modified title or to rollback to the defau…
…lt 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.)
  • Loading branch information
Kusal KC committedApr 22, 2020
commitd05a8261b1683e6c366687c6bace99d0c753be6b
12 changes: 9 additions & 3 deletionsindex.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
'use strict';
let{ useEffect}=require('react');
let{ useState, useEffect}=require('react');

functionuseDocumentTitle(title,retainOnUnmount=false){
const[defaultTitle,,]=useState(document.title);

functionuseDocumentTitle(title){
useEffect(()=>{
document.title=title;
},[title])

return()=>{
if(!retainOnUnmount)document.title=defaultTitle;
};
},[title]);
}

module.exports=useDocumentTitle;

[8]ページ先頭

©2009-2025 Movatter.jp