Last active
June 29, 2021 14:19
-
-
Save apexskier/a27daa87798c77c89e4fdfa50904ca57 to your computer and use it in GitHub Desktop.
useDocumentTitle template literal hook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
export function useDocumentTitle( | |
strings: TemplateStringsArray, | |
...args: ReadonlyArray<string> | |
): void { | |
React.useEffect(() => { | |
let title = ""; | |
strings.forEach((part, i) => { | |
title += part; | |
if (args[i]) { | |
title += args[i]; | |
} | |
}); | |
document.title = title; | |
}, args); | |
} | |
/* | |
useDocumentTitle`App | ${variable}` | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment