Skip to content

I want to give navbar of landing page some special style. But I don't know how to do it. #5288

Answered by slorber
Goddywu asked this question in Q&A
Discussion options

You must be logged in to vote

Hi

Using useEffect, the static HTML is already rendered to the user when your homepage class is inserted by the effect.
It is not a good fit because it will create some fouc / layout shift issues as the navbar will be first visible and then disappear after React hydration.

One solution to apply a className to the html/body tags on a per-page basis is to use the Head component (behind the scene it's using https://github.com/nfl/react-helmet)

import React from 'react';
import Head from '@docusaurus/Head';

export default function HomePage() {
  return (
    <>
      <Head>
        <body className="homepage" />
      </Head>
      <Layout>
         <h1>My HomePage</h1>
      </Layout>
    </>

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Goddywu
Comment options

Answer selected by Goddywu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants