Languages
[Edit]
EN

React - set web page title dynamically

0 points
Created by:
Frida-Timms
667

In this article, we would like to show you how to set web page title dynamically in React.

Quick solution:

useEffect(() => {
    document.title = 'Example title';
}, []);

 

Practical example

In this example, we use the useEffect hook to set document.title. Using the hook with the second argument set to an empty array ([]), the effect will be applied only once, on the app render. 

App.js file:

import React from 'react';
import { useEffect } from 'react';

const App = () => {
    useEffect(() => {
        document.title = 'Example title';
    }, []);

    return <div>App body here</div>;
};

export default App;

Result:

React - set web page title dynamically
React - set web page title dynamically - result

See also

  1. React - useEffect hook
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join