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

Changed the exemple of dynamic icons using NextJS #1580

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

morrisseybr
Copy link

This pr resolves the issue #1576.

@github-actions github-actions bot added 📖 documentation Improvements or additions to documentation 🌍 site Has to do something with the Lucide website labels Sep 27, 2023
@github-actions github-actions bot added the Stale label Oct 28, 2023
@dani-z
Copy link

dani-z commented Oct 30, 2023

Tried this locally, but unfortunately, it crashed my app. Are you sure this works with Next 13+ App router? Here's my error
image

@github-actions github-actions bot removed the Stale label Oct 31, 2023
@morrisseybr
Copy link
Author

Tried this locally, but unfortunately, it crashed my app. Are you sure this works with Next 13+ App router? Here's my error image

Can you show your implementation and the use of the example that you are doing?

Copy link
Member

@jguddas jguddas left a comment

Choose a reason for hiding this comment

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

👍 from me.

IMO we should remove the dynamicIconImports file, it's an antipattern and only leads to performance bottlenecks and flickering.

And hey, you can do this other ways such as described by your change here.

@KajSzy
Copy link

KajSzy commented Nov 23, 2023

Tried this locally, but unfortunately, it crashed my app. Are you sure this works with Next 13+ App router? Here's my error image

Can you show your implementation and the use of the example that you are doing?

I think his issue is that dynamicIconImports uses kebab-case icon names, while your apporach requires PascalCase
I've stumbled at exactly the same issue in my project that I very recently moved from non-optimized generic component to the one using dynamicIconImports
But as reported in issue the slowness of dev server brought me here

@bernatfortet
Copy link

@KajSzy converting the name to pascal case solved my issue. Dev server is super fast now. Thanks!

@ben519
Copy link

ben519 commented Dec 15, 2023

@morrisseybr this only works client-side. Any idea how to make it work within a Server Component?

@github-actions github-actions bot added the Stale label Jan 18, 2024

export default Icon
export default Icon;
```

##### NextJS Example

Copy link
Member

Choose a reason for hiding this comment

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

We should make separate sections for the App router and pages router.

Pages router should use the docs like it was before.

And create a new section specially targeting the App Router.
With this code example:

import { LucideProps, icons } from 'lucide-react';

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

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

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

export default Icon;

Choose a reason for hiding this comment

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

Hi, so is this the solution for dynamic import with the app router?

@lucide-icons lucide-icons deleted a comment from github-actions bot Feb 12, 2024
@ericfennis ericfennis removed the Stale label Feb 12, 2024
@lucide-icons lucide-icons deleted a comment from github-actions bot Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📖 documentation Improvements or additions to documentation 🌍 site Has to do something with the Lucide website
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants