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

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

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.)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743766563a4503585.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信