Hiimdjango
Hiimdjango

Reputation: 620

WithStyles injected props type

I am wrapping my class component with material UI withStyles to inject classes as a property.

export default withStyles(styles)(myComponent)

I have

const styles = ( (theme:Theme) => createStyles({className:CSS_PROPERTIES})

I am trying to declare an interface for my props as follows

interface MyComponentProps { classes : any }

What should I put instead of ANY ?

Upvotes: 1

Views: 362

Answers (1)

itaydafna
itaydafna

Reputation: 2086

Based on this documentation piece, here is how you should do it:

import { withStyles, createStyles, Theme, WithStyles } from '@material-ui/core';

const styles = (theme:Theme) => createStyles({className:CSS_PROPERTIES})

interface MyComponentProps extends WithStyles<typeof styles> {
    // you can type additional none-style related props of MyComponent here..
}

const MyComponent = ({ classes }: MyComponentProps) => {

     // your component logic ....

};

export default withStyles(styles)(myComponent)

Upvotes: 2

Related Questions