Ask Your Question
0

What is the method to immediately modify the title of a React page upon loading?

asked 2021-06-26 11:00:00 +0000

devzero gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-02-24 16:00:00 +0000

pufferfish gravatar image

You can modify the title of a React page upon loading by updating the document title in the useEffect hook of your main component, like this:

import React, { useEffect } from 'react';

function App() {
  useEffect(() => {
    document.title = "New Title"
  }, [])

  return (
    <div>
      {/* Your App content */}
    </div>
  );
}

export default App;

This code will modify the document title to "New Title" as soon as the component is mounted.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-06-26 11:00:00 +0000

Seen: 11 times

Last updated: Feb 24 '23