Skip to content

Commit

Permalink
perf: ⚡️ change title only if it changed
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Aug 31, 2021
1 parent c6a0a75 commit 51ef8d9
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/useTitle.ts
Expand Up @@ -10,7 +10,9 @@ const DEFAULT_USE_TITLE_OPTIONS: UseTitleOptions = {

function useTitle(title: string, options: UseTitleOptions = DEFAULT_USE_TITLE_OPTIONS) {
const prevTitleRef = useRef(document.title);
document.title = title;

if (document.title !== title) document.title = title;

useEffect(() => {
if (options && options.restoreOnUnmount) {
return () => {
Expand Down

0 comments on commit 51ef8d9

Please sign in to comment.