Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Refreshing the page will reset it to light #299

Open
Pszz opened this issue Jun 12, 2024 · 1 comment
Open

[Bug]: Refreshing the page will reset it to light #299

Pszz opened this issue Jun 12, 2024 · 1 comment
Labels
bug Something isn't working triage

Comments

@Pszz
Copy link

Pszz commented Jun 12, 2024

What happened?

When I setTheme toggle, LocalStorage successfully becomes dark.
But when I refresh the page, it is reset to light

image
image

  • providers.tsx
<NextUIProvider>
    <ThemeProvider attribute="class">
      {children}
    </ThemeProvider>
</NextUIProvider>
  • component.tsx
'use client'
import { useTheme } from 'next-themes'
import { Switch } from '@nextui-org/react'
import React from 'react'

export function DarkMode() {
  const { setTheme, theme } = useTheme()
  return (
    <Switch
      size="sm"
      aria-label="Dark Mode"
      defaultSelected={theme === 'dark'}
      onValueChange={(isSelected) => {
        setTheme(isSelected ? 'dark' : 'light')
      }}
    />
  )
}

Version

"next-themes": "^0.3.0",

What browsers are you seeing the problem on?

Chrome

@Pszz Pszz added bug Something isn't working triage labels Jun 12, 2024
@merzainc
Copy link

Can help reproduce this so i can help or at least figure out the issue. You can share the repository if possible.

I suggest using a different storage key.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage
Projects
None yet
Development

No branches or pull requests

2 participants