donavon / use-dark-mode

A custom React Hook to help you implement a "dark mode" component.
MIT License
1.28k stars 100 forks source link

Flashing with styled-components #61

Closed talohana closed 3 years ago

talohana commented 3 years ago

I am using styled-components and use-dark-mode with default config, both the plugin and the hook itself. When dark mode is enabled and I refresh the page I still get colors flashing.

I have a Layout.tsx component that includes:

const GlobalStyles = createGlobalStyle`
    body {
        transition: all 0.5s linear;

        &.dark-mode {
          background-color: #1f1f1f;
          color: #dfe6e9;
        }

        &.light-mode {
          background-color: #ecf0f1;
          color: #1f1f1f;
        }
    }
`

which is then included in the layout component:

export const Layout = ({ children }) => {
    <div>
        <GlobalStyles />
        {children}
    </div>
}
AlfieJones commented 3 years ago

Hi, I'm having a similar issue. How did you fix it?

talohana commented 3 years ago

Hi, I'm having a similar issue. How did you fix it?

Honestly, I can't remember. I migrated to tailwind css which have dark mode support.