You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guide/packages/lucide-react.md
+9-96Lines changed: 9 additions & 96 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -85,108 +85,21 @@ const App = () => (
85
85
);
86
86
```
87
87
88
-
## One generic icon component
88
+
## Dynamic Icon Component
89
89
90
90
It is possible to create one generic icon component to load icons, but it is not recommended.
91
+
Since it is importing all icons during build. This increases build time and the different modules it will create.
91
92
92
-
::: danger
93
-
The example below imports all ES Modules, so exercise caution when using it. Importing all icons will significantly increase the build size of the application, negatively affecting its performance. This is especially important to keep in mind when using bundlers like `Webpack`, `Rollup`, or `Vite`.
93
+
`DynamicIcon` is useful for applications that want to show icons dynamically by icon name. For example, when using a content management system with where icon names are stored in a database.
94
94
95
-
This is not the case for the latest NextJS, because it uses server side rendering. The icons will be streamed to the client when needed. For NextJS with Dynamic Imports, see [dynamic imports](#nextjs-example) section for more information.
96
-
:::
95
+
For static use cases, it is recommended to import the icons directly.
97
96
98
-
### Icon Component Example
97
+
The same props can be passed to adjust the icon appearance. The `name` prop is required to load the correct icon.
99
98
100
99
```jsx
101
-
import { icons } from'lucide-react';
102
-
103
-
constIcon= ({ name, color, size }) => {
104
-
constLucideIcon= icons[name];
105
-
106
-
return<LucideIcon color={color} size={size} />;
107
-
};
108
-
109
-
exportdefaultIcon;
110
-
```
111
-
112
-
#### Using the Icon Component
113
-
114
-
```jsx
115
-
importIconfrom'./Icon';
116
-
117
-
constApp= () => {
118
-
return<Icon name="Home"/>;
119
-
};
120
-
121
-
exportdefaultApp;
122
-
```
123
-
124
-
#### With Dynamic Imports
125
-
126
-
Lucide react exports a dynamic import map `dynamicIconImports`, which is useful for applications that want to show icons dynamically by icon name. For example, when using a content management system with where icon names are stored in a database.
127
-
128
-
When using client side rendering, it will fetch the icon component when it's needed. This will reduce the initial bundle size.
129
-
130
-
The keys of the dynamic import map are the lucide original icon names (kebab case).
In NextJS, [the dynamic function](https://nextjs.org/docs/pages/building-your-application/optimizing/lazy-loading#nextdynamic) can be used to dynamically load the icon component.
161
-
162
-
To make dynamic imports work with NextJS, you need to add `lucide-react` to the [`transpilePackages`](https://nextjs.org/docs/app/api-reference/next-config-js/transpilePackages) option in your `next.config.js` like this:
0 commit comments