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

Using Next.js dynamic import to create a generic icons component can effectively reduce client-side component re-rendering issues. #2081

Open
2 of 14 tasks
HOJOON07 opened this issue Apr 17, 2024 · 0 comments
Labels
💡 idea New ideas

Comments

@HOJOON07
Copy link

HOJOON07 commented Apr 17, 2024

Package

  • lucide
  • lucide-angular
  • lucide-flutter
  • lucide-preact
  • lucide-react
  • lucide-react-native
  • lucide-solid
  • lucide-svelte
  • lucide-vue
  • lucide-vue-next
  • Figma plugin
  • all JS packages
  • site

Description

In the sidebar and navigation bar components, I was importing each icon component and using icons via the name attribute. However, every time an icon was clicked or an event occurred, all the icon components exhibited a flickering issue.

Use cases

I was able to resolve it by adding React.memo.

import dynamic from 'next/dynamic';
import { memo } from 'react';
import { LucideProps } from 'lucide-react';
import dynamicIconImports from 'lucide-react/dynamicIconImports';

interface IconProps extends LucideProps {
  name: keyof typeof dynamicIconImports;
}

const Icon = memo(({ name, ...props }: IconProps) => {
  const LucideIcon = dynamic(dynamicIconImports[name]);

  return <LucideIcon {...props} />;
});

export default Icon;

Checklist

  • I have searched the existing issues to make sure this bug has not already been reported.
@HOJOON07 HOJOON07 added the 💡 idea New ideas label Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💡 idea New ideas
Projects
None yet
Development

No branches or pull requests

1 participant