-
Notifications
You must be signed in to change notification settings - Fork 3
feat: improve performance using uuid in key instead index array position #3
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,11 +43,17 @@ export function Carousel({ | |
scrollSliderPrevious(slider); | ||
} | ||
|
||
function uuid() { | ||
return ( | ||
Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15) | ||
); | ||
} | ||
|
||
return ( | ||
<div className="carousel"> | ||
<div ref={slider} className="carousel__slider"> | ||
{children.map((child, index) => ( | ||
<div key={index} className="carousel__slide"> | ||
{children.map((child) => ( | ||
<div key={uuid()} className="carousel__slide"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based on this, should not we avoid calling the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you're right, in this case we could use a simple implementation, like this: {children.map((child, index) => (
<div key={`carouselItem${index}`} className="carousel__slide">
{child}
</div>
))} interpolate the index list with a generic string |
||
{child} | ||
</div> | ||
))} | ||
|
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.
Have you considered using crypto.randomUUID? Does it has any downside for this purpose?
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.
Of course, my first option was that, but maybe in local develop crypto web api will not work because only runs in secure contexts (https)