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

[VariableSizeList] itemKey is not being passed into the itemSize function #406

Closed
c06e opened this issue Jan 24, 2020 · 1 comment
Closed

Comments

@c06e
Copy link

c06e commented Jan 24, 2020

Shouldn't the key value that is passed back from the itemKey function be passed into the itemSize function or am I not understanding this properly? In a perfect world, it would make sense to have the itemKey passed into the itemSize and in addition to that, have the data passed in as a second parameter to the itemSize function as well so that if someone wanted to run calculations based off of the data, they could. As it stands right now, my list gets rendering issues when i make any changes to my data when I merge my data.

"data": {
    "99": {
        "uniqueId": 99,
        "name": "bob"
    }
}
const getItemKey = (idx, data) => {
    const { uniqueId } = data[idx];
    return uniqueId;
};
const getItemSize = (idx) => {
    // 1) idx is zero based array index and NOT my uniqueId from getItemKey
    // 2) FEATURE REQUEST: Add data as a parameter, like getItemSize, so that math could be done
    //    to determine the height of the item.
    // ....
};

<AutoSizer>
    {({ height, width }) => (
        <VariableSizeList
           height={height}
           width={width}
           estimatedItemSize={88}
           itemKey={getItemKey}
           itemSize={getItemSize}
           itemCount={dataCount}
           itemData={data}
        >
           {ListRowItem}
        </VariableSizeList>
    )}
</AutoSizer>
@bvaughn
Copy link
Owner

bvaughn commented Jan 24, 2020

I think this issue is a misunderstanding 😄 Hopefully the below answer helps clear things up.

Shouldn't the key value that is passed back from the itemKey function be passed into the itemSize function or am I not understanding this properly? In a perfect world, it would make sense to have the itemKey passed into the itemSize

The itemSize function accepts an index. It can convert that value to a key, if that's useful, by calling your own e.g. getItemKey function, but I don't think this is generally required. itemSize function is responsible for determining the size of a specific item within the array. The key is something React uses to efficiently re-render when things move around within the array. These are different concerns.

and in addition to that, have the data passed in as a second parameter to the itemSize function as well so that if someone wanted to run calculations based off of the data, they could.

See this comment:
#90 (comment)

@bvaughn bvaughn closed this as completed Jan 24, 2020
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

2 participants