@material-ui/styles: Usage in a Class Component?
See original GitHub issueHow 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:
Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See https://fb.me/react-invalid-hook-call for tips about how to debug and fix this problem.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:17 (7 by maintainers)
Top Results From Across the Web
How to use useStyle to style Class Component in Material Ui
You can do it like this: import { withStyles } from "@material-ui/core/styles"; const styles = theme => ({ root: { backgroundColor: "red" } ......
Read more >How to customize - Material UI - MUI
Learn how to customize Material UI components by taking advantage of different strategies for specific use cases.
Read more >Material UI withStyles() for Class-based Components in React
In this example, you can get to know how we can use Material UI withStyles(HOC) for class-based components. To get access to theme...
Read more >material-ui/styles: Usage in a Class Component? · Issue #15820
How does one use the makeStyles API within a class component? The documentation only shows examples for function components.
Read more >The Easiest Way to Style your Material-UI Components
The makeStyles function returns a React hook that we can use in a functional component to access the styles and classes. Then, we...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
i used
withStyles
instead ofmakeStyle
like this…You can’t use the hooks inside a class component. You need a functionnal component or to use the higher order (
withStyles
).