Git Product home page Git Product logo

Comments (4)

pacocoursey avatar pacocoursey commented on May 20, 2024

How is this better than returning undefined, as the hook currently does? It's documented in the README that you need to be careful about hydration mismatch: https://github.com/pacocoursey/next-themes#avoid-hydration-mismatch

from next-themes.

remorses avatar remorses commented on May 20, 2024

I think returning undefined in useTheme is not really helpful, i cannot use useTheme directly without using first useMount

What about adding an argument defaultTheme to useTheme?

import { useTheme } from 'next-themes'

const ThemeChanger = () => {

  const { theme, setTheme } = useTheme({ defaultTheme: 'light' })

  return (
    <div>
      The current theme is: {theme}
      <button onClick={() => setTheme('light')}>Light Mode</button>
      <button onClick={() => setTheme('dark')}>Dark Mode</button>
    </div>
  )
}

This would make things a lot easier

from next-themes.

pacocoursey avatar pacocoursey commented on May 20, 2024

If you already know the default theme... why not just use it directly?

const { theme = 'light', setTheme } = useTheme()

This way if theme is undefined, it will become 'light' instead :)

from next-themes.

pacocoursey avatar pacocoursey commented on May 20, 2024

Closing because I think your use-case should be solved with the above, and I don't think another hook will help here.

from next-themes.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.