N
N
Nikolai2019-03-11 12:39:39
React
Nikolai, 2019-03-11 12:39:39

Which of the options is more optimized for destructuring?

React has the React-Icons module.
To get a specific icon, you need to do this: But sometimes the icon needs to be called dynamically, there is this option:
import { MdMailOutline } from "react-icons/md";

import * as MdIcon from "react-icons/md";

const Icon = MdIcon["MdLocalPhone"];

<Icon />

But with such an import, all icons are imported, does this affect performance?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Demian Smith, 2019-03-11
Demidovets @Nik_o_lay

This affects the final size of the bundle.
Webpack does tree shaking: only includes what was imported. In the first case, only one icon will be connected. In the second, everything, even if you use only one. Therefore, the first option is always preferable.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question