Next.js Discord

Discord Forum

Override next/head title tag using document.title

Unanswered
Japanese common catfish posted this in #help-forum
Open in Discord
Japanese common catfishOP
When I load my app, I set the title using the next/head component. However, I later want to update the title (both in the head and in the browser tab) using document.title, but it seems this value always gets reset to the initial value that was set using the next/head component.

FWIW here is how I am trying to update the title.

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

5 Replies

Japanese common catfishOP
Thanks, that is what I am currently doing, but my specific issue is wanting to update the value as infinite scroll items come into view when scrolling down. (This is not an issue, using <Head /> like you said.) But I also want to update the value to the old ones when scrolling back up. So I thought an imperative set of document.title would be the most straightforward.
Just do it the declarative react way
Japanese common catfishOP
I agree. Possibly I need to revisit my component tree and when I am rendering/updating the next/head component. Thanks!