Home > database >  How can I dynamically change title in Vite React?
How can I dynamically change title in Vite React?

Time:12-11

Vite React template has a file called index.html at the root of the project.

The way I understood, this file is static.

I want to change the title of each page based individually.

I know I can use useEffect in each page and set the title using simple vanilla JS.

But I wonder if there is a better more standard react-y way to do that?

CodePudding user response:

You can use react-helmet package, it enables you to add head tag in any component that you want

CodePudding user response:

Using useEffect seems pretty reasonable. You can encapsulate it into your own useTitle hook for more clarity (see for instance https://www.30secondsofcode.org/react/s/use-title).

  • Related