Last active
July 8, 2021 09:40
-
-
Save tjinlag/4acbf1dcfb1ef6eafc543731e814c7ea to your computer and use it in GitHub Desktop.
React custom hook: set document title when enter a page
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
const DEFAULT_TITLE = "Your default title"; | |
const useTitle = (title) => { | |
useEffect(() => { | |
document.title = title || DEFAULT_TITLE; | |
}, [title]); | |
}; | |
export default useTitle; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment