Skip to content
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

'AutoSizer' cannot be used as a JSX component #1739

Closed
mbagatini opened this issue Apr 17, 2022 · 21 comments
Closed

'AutoSizer' cannot be used as a JSX component #1739

mbagatini opened this issue Apr 17, 2022 · 21 comments

Comments

@mbagatini
Copy link

Hello team! I'd like to request some help, I am facing an issue in typescript, check it out:

Bug Report

Repo:
https://github.com/mbagatini/05-performance

Component:
src/components/SearchResultsVirtualized.tsx

What is the current behavior?

I'm getting the error "'AutoSizer' cannot be used as a JSX component." The same happens with List.

image
image

If you need more details, please let me know.

What is the expected behavior?

To solve the errors that are happening.

Which versions of React and react-virtualized, and which browser / OS are affected by this issue? Did this work in previous versions of react-virtualized?

Browser Edge
OS Windows 10
React 18.0.0
React DOM 18.0.0
react-virtualized 9.22.3
@rebelliard
Copy link
Contributor

I believe this is caused by an incompatible version of react in your repository (^18), whereas the current peer dependency of react-virtualized dictates ^17.0.1.

@mbagatini
Copy link
Author

Hi Rafael!

I have updated the dependencies:

  "dependencies": {
    "next": "12.1.5",
    "react": "^17.0.0",
    "react-dom": "17.0.1",
    "react-virtualized": "^9.22.3"
  },

But the error with the List component persists:

image
image

Am I doing something wrong?

@rebelliard
Copy link
Contributor

🤔. I'll try to reproduce it in a sandbox tonight.

@sohhamm
Copy link

sohhamm commented Apr 27, 2022

facing the exact same issue

@tippfelher
Copy link

tippfelher commented Apr 27, 2022

Ran into the same issue and solved it with this method.

Using react*@18.0.0 in my project.

Thus I had to add

  "resolutions": {
    "@types/react": "18.0.0",
    "@types/react-dom": "18.0.0"
  }

to my composer.json and run yarn after this.

@mbagatini
Copy link
Author

Thanks a lot @tippfelher! It solved the issue perfectly.

@mohituprim
Copy link

By downgrading @types/react version worked for me

"dependencies": {
"@types/react": "^17.0.0",
}

@Reed-Anderson
Copy link

Is there a similar solution for npm users?

@wind4gis
Copy link

"resolutions": { "@types/react": "17.0.0" }

Seems like this can be solved

@mttetc
Copy link

mttetc commented Jun 29, 2022

This shouldn't be happening and this issue shouldn't be closed.

@AChristoff
Copy link

Is there a way we can enjoy a new version compatible with the new react versions 17 18.... React-virtualized awesome but it is not touched for more than two years : /

@khRasikh
Copy link

khRasikh commented Aug 8, 2022

I have faced the same issue.
Screenshot 2022-08-08 at 09 31 34

@damiangreen
Copy link

This case needs re-opening

@uwemneku
Copy link

uwemneku commented Oct 1, 2022

While working with a turbo repo, none of the suggestions above worked for me. I had to type cast

import {
  AutoSizer as _AutoSizer,
  List as _List,
  ListProps,
  AutoSizerProps,
} from "react-virtualized";

const List = _List as unknown as FC<ListProps>;
const AutoSizer = _AutoSizer as unknown as FC<AutoSizerProps>;

@sohammondal
Copy link

While working with a turbo repo, none of the suggestions above worked for me. I had to type cast

import {
  AutoSizer as _AutoSizer,
  List as _List,
  ListProps,
  AutoSizerProps,
} from "react-virtualized";

const List = _List as unknown as FC<ListProps>;
const AutoSizer = _AutoSizer as unknown as FC<AutoSizerProps>;

This solved the issue for me without the need to downgrade React.

@jeespu
Copy link

jeespu commented Nov 9, 2022

While working with a turbo repo, none of the suggestions above worked for me. I had to type cast

import {
  AutoSizer as _AutoSizer,
  List as _List,
  ListProps,
  AutoSizerProps,
} from "react-virtualized";

const List = _List as unknown as FC<ListProps>;
const AutoSizer = _AutoSizer as unknown as FC<AutoSizerProps>;

I can't thank you enough. Fought with this issue for two days and downgrading React because of just one library felt like a red flag.

@mleister97
Copy link

While working with a turbo repo, none of the suggestions above worked for me. I had to type cast

import {
  AutoSizer as _AutoSizer,
  List as _List,
  ListProps,
  AutoSizerProps,
} from "react-virtualized";

const List = _List as unknown as FC<ListProps>;
const AutoSizer = _AutoSizer as unknown as FC<AutoSizerProps>;

Thanks a lot. This should be fixed, isn't the library updated anymore?

@dmitryshostak
Copy link

import { FC } from 'react';
import {
  AutoSizer as _AutoSizer,
  List as _List,
  InfiniteLoader as _InfiniteLoader,
  ListProps,
  AutoSizerProps,
  InfiniteLoaderProps,
} from 'react-virtualized';

export const VirtualizedList = _List as unknown as FC<ListProps> & _List;
// You need this one if you'd want to get the list ref to operate it outside React 👍 
export type VirtualizedListType = typeof VirtualizedList;

export const AutoSizer = _AutoSizer as unknown as FC<AutoSizerProps> & _AutoSizer;
export const InfiniteLoader = _InfiniteLoader as unknown as FC<InfiniteLoaderProps> & _InfiniteLoader;

@fabianboerner
Copy link

Hi, i still have this issue, why is it closed?

Drun555 pushed a commit to Drun555/iQbit that referenced this issue Jan 10, 2024
@mariorodriguespt
Copy link

Please reopen this

@MeganOosthoekKodiak
Copy link

running yarn dedupe fixed this for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests