Skip to content

Instantly share code, notes, and snippets.

@tjinlag
Last active July 8, 2021 09:40
Show Gist options
  • Save tjinlag/4acbf1dcfb1ef6eafc543731e814c7ea to your computer and use it in GitHub Desktop.
Save tjinlag/4acbf1dcfb1ef6eafc543731e814c7ea to your computer and use it in GitHub Desktop.
React custom hook: set document title when enter a page
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