Answers for "change react app 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
3

change title react

import React from 'react'
import ReactDOM from 'react-dom'


class Doc extends React.Component{
  componentDidMount(){
    document.title = "dfsdfsdfsd"
  }

  render(){
    return(
      <b> test </b>
    )
  }
}

ReactDOM.render(
  <Doc />,
  document.getElementById('container')
);
Posted by: Guest on May-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
0

how to change the title of create-react-app

You can find the source HTML file in the public folder of the generated project. 
You may edit the <title> tag in it to change the title from “React App” to anything else.
Posted by: Guest on June-19-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language