Skip to content

[Readme] Clear up hydration issue explanation #364

@GionnyBanana

Description

@GionnyBanana

In the readme you write that you need to be sure you are on client side to apply logic related to the themes.
I think you could add a section explaining that you can avoid that client side check if you use this library with something like tailwind, which has light and dark: theme classes always in the components so the server and client code is not mismatched.

Just use data attributes to set your theme.

  • Use @custom-variant dark (&:where([data-theme=dark], [data-theme=dark] *)); in your globals.css
  • Instruct next-theme to use data-theme as well by adding attribute="data-theme" to the ThemeProvider.

In this way you won't have hydration errors, because your classes never change and next-themes will simply modify the top data-theme to change your app theme. (Again, your components will have to use the dark: tailwind pattern for dark theme colors)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions