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
@material-ui/styles: Usage in a Class Component? #15820
Comments
You can't use the hooks inside a class component. You need a functionnal component or to use the higher order ( |
I'm closing, if we see similar report, I think that we should document it. |
@oliviertassinari : But if app is declared as a class how do I do it? |
@Angelk90 You should use the higher order component API: #15820 (comment) ( |
According to your documentation, the https://material-ui.com/styles/basics/ That's why I down-voted your answer. |
@oliviertassinari |
As suggested by @ghosh-jaideep ,
inside a class component? |
i used import React from 'react';
import { withStyles } from '@material-ui/core/styles';
const styles = (theme) => ({
fab: {
position: 'fixed',
bottom: theme.spacing(2),
right: theme.spacing(2),
},
});
class LoginComponent extends React?Component {
render() {
const { classes } = this.props;
/** your UI components... */
}
}
export default withStyles(syles)(LoginComponent); |
@Ess-Soft How
It will be more useful if you share code snippet of parent component. |
I did the same thing as @Ess-Soft and added widthTheme before withStyles then you can use |
Can someone explain the with styles thing. I can honestly say when I see stuff like this I think lol come on man Angular is just so much more normal. 3 hours today searching and looking for answers and then I find this. |
@xtianus79 This API works with class components too: https://material-ui.com/styles/basics/#higher-order-component-api. |
@oliviertassinari can you show mean an example of it with the grid? lol that is what I am trying to do and I am stuck right there. I am using makeStyles and createStyles and I cant' figure out how to do it without a function? Can you help with that. |
@xtianus79 You will find more help on StackOverflow |
This comment has been minimized.
This comment has been minimized.
Ummm. still even https://material-ui.com/styles/basics/#higher-order-component-api doesn't answer how to use 'theme' ? why only supports functional components with Hooks? people do have legacy code or the need for class based components. |
@DewangS See the |
How does one use the
makeStyles
API within a class component? The documentation only shows examples for function components.When I try to use this within a class component's
render
method, I get the following error:The text was updated successfully, but these errors were encountered: