Git Product home page Git Product logo

Comments (2)

animeshchat avatar animeshchat commented on May 20, 2024 1

@pacocoursey - Thanks for your reply!

My web app has a combination of server side and client side rendering, and supports multiple themes. The user may have saved theme preference, which needs to be fetched.

If no themes preferences are present for the user, the app will rely on the system defaults.
You're right - maybe I don't need to use localStorage but its useful when it comes to propagating changes across tabs/sessions.

next-themes was really useful for the above reasons. Saved me from the task of building in all that logic.

If only it could support a way to set initial theme. For eg.

**<ThemeProvider initTheme="dark" attribute="class">** 

Currently., I am fetching the preference on the server side and setting the theme (setTheme()) on the client side, which is causing the frontend to flash.

from next-themes.

pacocoursey avatar pacocoursey commented on May 20, 2024

Good question. Next-themes doesn't support this in a nice way right now, and it may not need to.

It sounds like you're server-rendering all your pages, so you can just include the theme as a body class with the initial HTML payload (getInitialProps in _document I believe). Then you don't need localStorage or the render-blocking inline script that next-themes injects.

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.