-
Notifications
You must be signed in to change notification settings - Fork 2
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
fix(list): Add uuid for each list item #179
Conversation
src/list/List.tsx
Outdated
@@ -46,6 +47,8 @@ function List<Item extends any>({ | |||
|
|||
if (listItemKeyGenerator) { | |||
key = listItemKeyGenerator(item, listItemTestId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should re-arrange the ifs:
if (listItemKeyGenerator) {
key = listItemKeyGenerator(item, listItemTestId);
// @ts-ignore
} else if (item && typeof item === "object" && item.id) {
// @ts-ignore
key = item.id;
} else {
key = uuidv4();
}
Because I believe currently we don't use id in any case. We override the first if
in 43 in the else
in 50.
Also I think it's time to create a util for this and clean up the component function body:
return <Fragment key={generateListItemKey({
item, listItemTestId, listItemKeyGenerator
})}>
{children(item, listItemTestId, index)}
</Fragment>;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated it, thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, thank you!
Description
uuid
package to generate unique IDs.listItemKeyGenerator
ortestid
props, generates uuid.testid
is not best practice. Because if list manipulate (add/remove an item or changing order) causes using wrong keys.Related Issue: #177