Skip to content

Commit

Permalink
docs dark mode: section for Next.js (#1137)
Browse files Browse the repository at this point in the history
Co-authored-by: Sebastian Sutu <[email protected]>
  • Loading branch information
SutuSebastian and Sebastian Sutu authored Nov 16, 2023
1 parent ca3370e commit c9f85fd
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions content/docs/customize/dark-mode.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,51 @@ export default function MyPage() {
}
```

## NextJS

In server side rendered applications, such as NextJS, to avoid page flicker (if `dark` mode is set) before NextJS hydrates the content, `ThemeModeScript` component must be rendered in `Head` component (see implementation below).

`ThemeModeScript` renders a script tag that sets `dark` or removes `dark` from `<html>` element before hydration occurs.

### App router

```tsx
// app/layout.tsx

import { ThemeModeScript } from 'flowbite-react';

export default function RootLayout({ children }) {
return (
<html>
<head>
<ThemeModeScript />
</head>
<body>{children}</body>
</html>
);
}
```

### Pages router

```tsx
// pages/_document.tsx

import { ThemeModeScript } from 'flowbite-react';

export default function Document() {
return (
<Html>
<Head>
<ThemeModeScript />
</Head>
<body>
<Main />
<NextScript />
</body>
</Html>
);
}
```

<div className="h-[20vh]" />

1 comment on commit c9f85fd

@vercel
Copy link

@vercel vercel bot commented on c9f85fd Nov 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.