Allow icons dynamic imports
See original GitHub issueHello ! 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:
- Created 2 years ago
- Reactions:3
- Comments:7 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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…
Is there any update on this topic?