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

ThemeProvider's theme prop is reactive? #57

Open
luiguild opened this issue Aug 14, 2024 · 0 comments
Open

ThemeProvider's theme prop is reactive? #57

luiguild opened this issue Aug 14, 2024 · 0 comments

Comments

@luiguild
Copy link

Steps to reproduce:
1 - npx degit solidjs/templates/ts my-app
2 - npm i -s solid-styled-components
3 - edit App.tsx with the follow content
4 - npm run dev

This super minimal example doesn't work:
App.tsx

import {styled, ThemeProvider} from "solid-styled-components";
import {createSignal} from "solid-js";

const dark = {
  colors: {
    primary: "black"
  }
};

const light = {
  colors: {
    primary: "white"
  }
};

const Container = styled('div')`
  width: 100vw;
  height: 100vh;
  background: ${props => props.theme?.colors.primary};
`;


export const App = () => {
  const [isDarkMode, setIsDarkMode] = createSignal(false);

  const toggleTheme = () => {
    setIsDarkMode(!isDarkMode());
  };

  return (
    <ThemeProvider theme={isDarkMode() ? dark : light}>
      <Container>
        <button onClick={toggleTheme}>{isDarkMode() ? "Light" : "Dark"} Mode</button>
      </Container>
    </ThemeProvider>
  );
};

What is the proper way to toggle between these themes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant