Skip to content

Conversation

@EnderRomantice
Copy link
Contributor

Currently, every time AnimatedList re-renders (e.g., when selectedIndex changes), new inline functions are created for onMouseEnter and onClick for each list item. This causes all AnimatedItem children to re-render unnecessarily, which can impact performance, especially with longer lists.

Solution

Refactored the event handlers to use React’s useCallback hook. This memoizes the functions, ensuring their references remain stable across renders. As a result, only the AnimatedItem that is actually affected will re-render.

Key Changes

Imported useCallback from React.
Wrapped handleItemMouseEnter, handleItemClick, and handleScroll in useCallback.
Updated the items.map() loop to call these memoized handlers.
Verification

This is a pure performance optimization. All existing functionality (mouse hover, click, keyboard navigation, scroll gradients) should work exactly as before with no breaking changes.

Copy link
Owner

@DavidHDev DavidHDev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool!

@DavidHDev DavidHDev merged commit 4c462bf into DavidHDev:main Nov 30, 2025
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

Successfully merging this pull request may close these issues.

2 participants