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

itemContent is getting called with 0 items in grouped array (GroupedVirtuoso) #319

Open
pdeleastar opened this issue Mar 22, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@pdeleastar
Copy link

itemContent is getting called with 0 items in a grouped Array with GroupedVirtuoso. With Virtuoso list this does not happen with an empty array.

Reproduction
I have created a sandbox with a GroupedVirtuoso and Virtuoso, both logging when they get called.
https://codesandbox.io/s/react-virtualized-grouped-oge5x?file=/src/App.js

 const emptyArray = new Array(0);

  /**
   * CONSOLE OUTPUT
   *
   * Grouped Virtuoso - itemContent called 0
   */
  return (
    <div>
      <GroupedVirtuoso
        style={{ height: "200px", width: "200px" }}
        groupCounts={[emptyArray.length]}
        groupContent={(index) => {
          return <div>Group {index}</div>;
        }}
        itemContent={(index) => {
          /**
           * itemContent is getting called when there
           * are 0 elements in the group.
           */
          console.log("Grouped Virtuoso - itemContent called", index);
          return <div>{index}</div>;
        }}
      />

      <Virtuoso
        style={{ height: "200px", width: "200px" }}
        totalCount={emptyArray.length}
        itemContent={(index) => {
          /**
           * itemContent does not get called with there
           * are 0 elements in the list
           */
          console.log("Virtuoso - itemContent called", index);

          return <div>Item {index}</div>;
        }}
      />
    </div>
  );

Thanks,
Pierre

@pdeleastar pdeleastar added the bug Something isn't working label Mar 22, 2021
@petyosi
Copy link
Owner

petyosi commented Mar 23, 2021

Supporting empty groups, (especially in the initial render) is quite complicated, due to the "probe" rendering cycle. I may eventually find a way to fix that, but for now, I would suggest that you skip the rendering of the component if you have empty groups.

@Hideman85
Copy link

Similar issue:

  /**
   * CONSOLE OUTPUT
   *
   * Grouped Virtuoso - itemContent called 0 0 A
   * Grouped Virtuoso - itemContent called 0 0 B // Sorry? Expected 1 1 B
   */
  return (
    <div>
     <GroupedVirtuoso
        style={{ height: "200px", width: "200px" }}
        data={['A', 'B']}
        groupCounts={[1, 1]}
        groupContent={(index) => {
          return <div>Group {index}</div>;
        }}
        itemContent={(index, groupIndex, item) => {
          /**
           * itemContent is getting called when there
           * are 0 elements in the group.
           */
          console.log("Grouped Virtuoso - itemContent called", index, groupIndex, item);
          return <div>{index}</div>;
        }}
      />
    </div>
  );

In addition I would add my voice to #235 the props are counterintuitive (here index is not relative to the group but to the flattened array)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants