ThemeProvider cannot be used as a JSX component
See original GitHub issueEnvironment
System:
- OS: macOS 12.3.1
- CPU: (4) x64 Intel® Core™ i5-7360U CPU @ 2.30GHz
- Memory: 30.26 MB / 8.00 GB
- Shell: 5.8 - /bin/zsh
Binaries:
- Node: 17.6.0 - /usr/local/bin/node
- Yarn: 3.2.0 - /usr/local/bin/yarn
- npm: 8.5.1 - /usr/local/bin/npm
npmPackages:
- babel-plugin-styled-components: ^2.0.7 => 2.0.7
- styled-components: ^5.3.5 => 5.3.5
Reproduction
React: 18.0.0
When using ThemeProvider TypeScript says:
TS2786: ‘ThemeProvider’ cannot be used as a JSX component. Its instance type ‘Component<ThemeProviderProps<any, any>, any, any>’ is not a valid JSX element. The types returned by ‘render()’ are incompatible between these types. Type ‘import(“/…/node_modules/@types/react-dom/node_modules/@types/react/index”).ReactNode’ is not assignable to type ‘React.ReactNode’. Type ‘{}’ is not assignable to type ‘ReactNode’.
Issue Analytics
- State:
- Created a year ago
- Comments:7
Top Results From Across the Web
Component cannot be used as a JSX component in React
Another common cause of the "Component cannot be used as a JSX component" error is when we return anything other than a JSX...
Read more >Component cannot be used as a JSX component. Its return ...
I'm currently getting the following error on the Todos component inside TodoApp.tsx : 'Todos' cannot be used as a JSX component.
Read more >themeprovider' cannot be used as a jsx component. its ...
When using ThemeProvider TypeScript says: TS2786: 'ThemeProvider' cannot be used as a JSX component. Its instance type 'Component<ThemeProviderProps<any, ...
Read more >'SVG' cannot be used as a JSX component.
'SVG' cannot be used as a JSX component. Its instance type 'InlineSVG' is not a valid JSX element. The types returned by 'render()'...
Read more >App can not be used as JSX component - react error - YouTube
Join this channel to get access to perks:https://www.youtube.com/channel/UCoSpmr2KNOxjwE_B9ynUmig/joinMy GearCamera ...
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
Hi, for now I just ignoring it with the
@ts-ignore(hotfix). This issue isn’t related with the styled-components itself, problem is with the@types/styled-componentswhich hasn’t been update yet.I was able to fix this issue by upgrading the react types library
yarn add -D @types/react@17.0.52