React Icons uses ES6 module imports, enabling modern bundlers to eliminate unused code:
import { FaBeer, FaCoffee } from "react-icons/fa";function Beverages() { return ( <div> <FaBeer /> <FaCoffee /> </div> );}// ✓ Only FaBeer and FaCoffee are included in your bundle
With proper tree-shaking, importing from react-icons/fa only bundles the icons you actually use, not the entire Font Awesome library.
Pros: Best tree-shaking, explicit dependencies, fast build times
Import from specific icon packs:
// Each icon pack is in its own subpathimport { FaBeer } from "react-icons/fa"; // Font Awesomeimport { MdHome } from "react-icons/md"; // Material Designimport { AiFillHeart } from "react-icons/ai"; // Ant Designimport { BiSearch } from "react-icons/bi"; // BoxIconsimport { BsCart } from "react-icons/bs"; // Bootstrap Icons
Pros: Organized by icon family, still tree-shakeable
For environments with build issues, import individual files:
import { FaBeer } from "@react-icons/all-files/fa/FaBeer";function Question() { return ( <h3> Lets go for a <FaBeer />? </h3> );}
Pros: Guaranteed tree-shaking, no bundler configuration neededCons: Slower installation, more verbose imports
// ✓ Goodimport { FaBeer } from "react-icons/fa";// ✓ Goodimport { FaBeer } from "@react-icons/all-files/fa/FaBeer";// ❌ Bad - imports everythingimport * as Icons from "react-icons/fa";
Verify bundler configuration
Ensure tree-shaking is enabled:
Set mode: 'production' in webpack
Enable sideEffects: false in optimization
Check package.json for "sideEffects": false
Use @react-icons/all-files
If tree-shaking isn’t working, use the alternative package:
npm install @react-icons/all-files
import { FaBeer } from "@react-icons/all-files/fa/FaBeer";
Trade-off: Slower installation, but guaranteed small bundle.
Split icon imports by route
Use code splitting to load icons only when needed:
// routes/Dashboard.jsximport { FaHome, FaUser } from "react-icons/fa";// routes/Settings.jsx import { FaCog, FaBell } from "react-icons/fa";// Only relevant icons load per route
React Icons SVG components have minimal runtime overhead compared to icon fonts. There’s no blocking network request for font files, and icons render immediately.