DEV Community

CHIN SHAN LEE
CHIN SHAN LEE

Posted on

[React] Render different title in your website

refer to : https://www.npmjs.com/package/react-helmet

Different title can helps user to recognize what content they are browsing now. Which is very important !

  1. Install react-helmet
    npm install --save react-helmet

  2. import react-helmet
    import { Helmet } from 'react-helmet';

  3. custom title
    const TITLE = 'custom-title';

  4. add html code
    <Helmet>
    <title>{ TITLE }</title>
    </Helmet>



Example :

import React, {useEffect} from 'react';
import '../../App.css';
import { Helmet } from 'react-helmet'

const TITLE = 'custom-title';

function ThePage() {
    return (
        <>
            <div className='page-container'>
                <Helmet>
                    <title>{ TITLE }</title>
                </Helmet>
                <div>
                    other content ...
                </div>
            </div>
        </>
    )
}

export default ThePage;
Enter fullscreen mode Exit fullscreen mode

Top comments (0)