-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
Components with withStyles() cannot be used as a JSX component. #32759
Comments
Please provide a CodeSandbox (https://mui.com/r/issue-template or https://mui.com/r/ts-issue-template), a link to a repository on GitHub, or provide a minimal code example that reproduces the problem. Here are some tips for providing a minimal example: https://stackoverflow.com/help/mcve |
The easiest way is to install
and open in VSCode such a file:
The which doesn't happen when |
Works for me. Take a look at this CodeSandbox. If you are using TypeScript, does your file have |
👋 Thanks for using MUI Core! We use GitHub issues exclusively as a bug and feature requests tracker, however, For support, please check out https://mui.com/getting-started/support/. Thanks! If you have a question on StackOverflow, you are welcome to link to it here, it might help others. |
The sample file has to have .js extension to reproduce the issue, sorry to not make it clear. When I change the extension to .tsx, the issue disappears. Still sounds like a bug to me, at least it did work fine previously. |
Works fine for me with Looks like something to do with your setup. |
OK, thanks. I guess that it might be related to VSCode only, possibly its bug, since I don't see how my setup could affect it (don't see any relevant VSCode Extension). |
My ProblemMy problem was that a MUI sub-dependency My Project Dependency Hierarchy
React 18 was just recently released. This explains why it seemed to have started failing all of a sudden even though it had been working at one point. It also explains why it worked at runtime, but not compile-time. Is this your problem too?Check your SolutionMy solution was to "pin" all "@types/react" dependencies to 16. This was accomplished with Yarn's LessonRemember to specify your dependencies' versions folks. |
Thanks for the solution @dperez3. It even worked in my monorepo. Reproducible steps:
If you see that your |
Duplicates
Latest version
Current behavior 😯
Whenever I try to use a component that contains withStyles(), I get TypeScript error "'Item' cannot be used as a JSX component."
This is in JS code that has
//@ts-check
enabled. No specific tsconfig, just the default VSCode configuration.The same happens with the latest mui v4 or v5.
Expected behavior 🤔
This used to work fine, but probably with some upgrade it stopped working.
Steps to reproduce 🕹
Steps:
export default withStyles(styles)(Item);
<Item />
Context 🔦
No response
Your environment 🌎
`npx @mui/envinfo`
The text was updated successfully, but these errors were encountered: