Answers for "change react js title"

2

react set title of page

import React, { useEffect } from 'react'
import ReactDOM from 'react-dom'

const App = () => {
  // This effect runs once, after the first render
  useEffect(() => {
    document.title = "This is a title"
  }, [])
  
  return <h1>Hello, World!</h1>
};

ReactDOM.render(
  <App />,
  document.getElementById('root')
);
Posted by: Guest on July-15-2020
0

react component title change

// create a new component Page.js

import { useEffect } from "react";

const Page = (props) => {
  useEffect(() => {
    document.title = props.title || "";
  }, [props.title]);
  return props.children;
};

export default Page;

//And then use Page in App.js

<Route
  path="/about"
	 <Page title="Index">
      <Index {...props} />
    </Page>
/>
<Route
  path="/profile"
    <Page title="Profile">
      <Profile {...props} />
    </Page>
/>
Posted by: Guest on October-26-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language