question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow icons dynamic imports

See original GitHub issue

Hello ! What about importing components like this : import IconFa2 from '@tabler/icons/IconFa2 ? With Next.js, we could then use this :

const IconFa2 = dynamic(() => import('@tabler/icons/IconFa2'));

Or more dynamic :

const Icon = dynamic(() => import(`@tabler/icons/${name}`));

Or maybe export a default, so we can :

const Icon = dynamic(() => import('@tabler/icons').then(mod => mod[name]))`;

What do you think ?

_Originally posted by @matha-io in https://github.com/tabler/tabler-icons/issues/126#issuecomment-829368683_

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:3
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
adambrgmncommented, May 3, 2021

Ah I see. But then you don’t mind including the full icon library in your code. But I guess publishing each icon as its own file would solve some parts and then you could use (await import(@tabler/icons/${icon})).default.

Note though that I don’t think it is possible to use template string literals with Next.js dynamic, but that is not a concern for this library. You would have to roll your own loading mechanism.

Another issue is in which format to publish the separate files. CommonJS or ESM? ESM is probably more future safe…

0reactions
sapkracommented, Sep 23, 2022

Is there any update on this topic?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dynamic import of react-icons - Stack Overflow
Is it possible to import dynamically react-icons if each of icon is a separate component? My code looks like this: import React from...
Read more >
Dynamic imports of Material UI Icons - Manuel Kruisz
Typically when we build sites with Material UI's icons, we just import the icon to use directly and insert it into our react...
Read more >
Dynamically Importing React Material Icons Using Webpack
It turns out we can leverage require to just use a convention-based method of dynamically importing the icons. Within a webpack context, it ......
Read more >
How to import icon component dynamically? #364 - GitHub
I note for posterity that the Sanity code I am using to set icons dynamically is as follows: import * as icons from...
Read more >
Add Icons with React | Font Awesome Docs
There are a few ways to add icons when using React. The easiest way is to use Dynamic Icon Importing which automatically imports...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found