Skip to content

createUseStyles with TypeScript #1553

Answered by erwstout
erwstout asked this question in Q&A
Discussion options

You must be logged in to vote

I think I've found the solution. The passing of theme/props to the classes still feels strange to me. Can anyone verify this is the correct way to do it? Thanks so much!

import React, { ReactNode } from "react";
import { createUseStyles, useTheme, ThemeProvider } from "react-jss";

interface Props {
  children: ReactNode;
  useRed: boolean;
}

interface PUTheme {
  colorPrimary: string;
  altColor: string;
}

const useStyles = createUseStyles({
  button: {
    background: ({
      theme,
      useRed
    }: {
      theme: PUTheme;
      useRed: Props["useRed"];
    }) => (useRed ? theme.altColor : theme.colorPrimary)
  },
  label: {
    fontWeight: "bold"
  }
});

const Button2: React.FC<P…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@erwstout
Comment options

@rtivital
Comment options

Answer selected by erwstout
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants