最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

next.js - next-themes forcedTheme="dark" not working - Stack Overflow

matteradmin2PV0评论

I'm using next-themes in my Next.js app. I want to force the theme to dark regardless of user preference.

I've set forcedTheme='dark', but:

  • The theme still changes based on the user's system settings.

  • I can manually switch themes using the DevTools theme emulator.

How can I enforce dark mode completely?

My layout.js:

import { ThemeProvider } from 'next-themes'
import './globals.css'

export default function RootLayout({ children }) {
    return (
        <html suppressHydrationWarning>
            <body>
                <ThemeProvider
                    forcedTheme='dark'
                    defaultTheme='dark'
                    attribute='class'
                    enableSystem={false}
                >
                    {children}
                </ThemeProvider>
            </body>
        </html>
    )
}

GitHub Repo:

Hosted URL: /

(Intent: I want users to use dark mode for now as the light mode is not fully ready yet.)

Post a comment

comment list (0)

  1. No comments so far