@tabler/icons-react、feather-icons-react 和 react-icons 都是在 React 项目中嵌入 SVG 图标的常用解决方案,但它们的维护模式和使用场景有所不同。
@tabler/icons-react 是 Tabler Icons 的官方 React 实现,提供大量风格一致的描边图标,更新频繁且维护活跃。
feather-icons-react 是 Feather Icons 的 React 封装之一,Feather 图标集本身设计简洁,但核心库已归档,社区维护状态不一。
react-icons 是一个聚合库,包含了 Feather、Tabler、FontAwesome 等数十个图标集,适合需要多种图标风格混合使用的项目,通过按需导入支持树摇优化。
在 React 项目中引入图标看似简单,但选型不当会导致包体积膨胀、风格不统一或后期维护困难。@tabler/icons-react、feather-icons-react 和 react-icons 代表了三种不同的解决思路:官方原生实现、特定图标集封装、以及全量聚合方案。我们从工程化角度深入对比。
导入语法的差异直接影响代码的可读性和 IDE 的智能提示体验。
@tabler/icons-react 使用标准的 ES6 命名导出。
// @tabler/icons-react
import { IconHome, IconUser } from '@tabler/icons-react';
function Navigation() {
return (
<nav>
<IconHome />
<IconUser />
</nav>
);
}
feather-icons-react 同样使用命名导出,但依赖具体封装版本。
// feather-icons-react
import { Home, User } from 'feather-icons-react';
function Navigation() {
return (
<nav>
<Home />
<User />
</nav>
);
}
react-icons 使用路径导入来区分图标集。
fi 代表 Feather,tb 代表 Tabler)。// react-icons
import { FiHome } from 'react-icons/fi';
import { TbUser } from 'react-icons/tb';
function Navigation() {
return (
<nav>
<FiHome />
<TbUser />
</nav>
);
}
图标的大小、颜色和线条粗细通常需要根据上下文调整,实现方式影响组件的复用性。
@tabler/icons-react 提供丰富的 Props 控制。
size、color、strokeWidth 等属性。// @tabler/icons-react
import { IconHome } from '@tabler/icons-react';
// 直接通过 props 调整
<IconHome size={32} color="red" strokeWidth={1.5} />
feather-icons-react 支持基础 Props。
size 和 color。strokeWidth 直接控制,需查文档。// feather-icons-react
import { Home } from 'feather-icons-react';
// 基础属性控制
<Home size={32} color="red" />
react-icons 统一了 Props 接口。
size、color 等通用属性。// react-icons
import { FiHome } from 'react-icons/fi';
// 统一属性接口
<FiHome size={32} color="red" />
图标库通常包含成千上万个图标,确保未使用的图标不被打包至关重要。
@tabler/icons-react 原生支持树摇。
// @tabler/icons-react
// 只导入用到的图标,未导入的不会打包
import { IconHome } from '@tabler/icons-react';
feather-icons-react 依赖封装实现。
// feather-icons-react
// 确保使用命名导入而非全量导入
import { Home } from 'feather-icons-react';
// 避免:import * as Icons from 'feather-icons-react'
react-icons 专为树摇设计。
// react-icons
// 正确:只打包 fi 集合中的 Home
import { FiHome } from 'react-icons/fi';
// 错误:可能导致全量打包
// import * as Icons from 'react-icons'
选择开源库时,维护活跃度直接决定项目未来的安全性。
@tabler/icons-react 处于活跃维护期。
// @tabler/icons-react
// 完整的 TypeScript 支持
import { IconHome } from '@tabler/icons-react';
// props 有完整的类型提示
feather-icons-react 存在潜在风险。
// feather-icons-react
// 需确认所选封装包的最后更新时间
import { Home } from 'feather-icons-react';
// 建议:若无强依赖,考虑迁移至更活跃库
react-icons 维护稳定。
// react-icons
// 即使 Feather 停止更新,react-icons 仍提供稳定入口
import { FiHome } from 'react-icons/fi';
| 特性 | @tabler/icons-react | feather-icons-react | react-icons |
|---|---|---|---|
| 图标风格 | 现代描边,风格统一 | 简洁描边,经典风格 | 聚合多种风格 |
| 导入方式 | 命名导出 IconHome | 命名导出 Home | 路径导出 FiHome |
| 定制能力 | 强 (支持 strokeWidth) | 中 (基础 props) | 强 (统一接口) |
| 维护状态 | ✅ 活跃 | ⚠️ 核心库已归档 | ✅ 活跃 |
| 适用场景 | 新项目中长期维护 | 遗留项目或特定设计 | 多图标集混合需求 |
@tabler/icons-react 像是精心打磨的专用工具 🔨——适合追求现代设计语言、需要长期维护的新项目。它的原生支持和活跃维护能减少未来的技术债务。
feather-icons-react 像是经典但停产的零件 🕰️——虽然设计经典,但核心库已停止更新。除非设计系统强绑定,否则不建议在新项目中作为首选,可考虑通过 react-icons 使用 Feather 集。
react-icons 像是多功能工具箱 🧰——适合需要灵活组合不同图标源的场景。它解决了“只有一个图标库不够用”的问题,且保持了统一的开发体验。
最终建议:对于大多数新 React 项目,优先考虑 @tabler/icons-react 以获得最佳一致性和维护性;若需多套图标混合,则选用 react-icons。尽量避免直接依赖已归档图标集的独立封装包。
如果你的项目需要混合使用多种图标集(如同时需要 Material Design 和 FontAwesome),或者希望减少依赖数量,请选择 react-icons。它通过统一的导入方式管理所有图标,适合快速原型开发或图标需求复杂的项目。
如果你的项目需要大量风格统一、现代感强的描边图标,且看重长期维护支持,请选择 @tabler/icons-react。它的官方原生支持意味着更好的类型定义和更少的兼容性问题,适合新建的企业级后台或 SaaS 产品。
仅当你的设计系统严格依赖 Feather 图标风格且无法迁移时才考虑此包。需注意 Feather 核心库已归档,社区封装版本众多,建议优先评估 react-icons 中的 Feather 集合或更活跃的 react-feather 以降低维护风险。
Include popular icons in your React projects easily with react-icons, which utilizes ES6 imports that allows you to include only the icons that your project is using.
yarn add react-icons
# or
npm install react-icons --save
example usage
import { FaBeer } from "react-icons/fa";
function Question() {
return (
<h3>
Lets go for a <FaBeer />?
</h3>
);
}
View the documentation for further usage examples and how to use icons from other packages. NOTE: each Icon package has it's own subfolder under react-icons you import from.
For example, to use an icon from Material Design, your import would be: import { ICON_NAME } from 'react-icons/md';
Note This option has not had a new release for some time. More info https://github.com/react-icons/react-icons/issues/593
If your project grows in size, this option is available. This method has the trade-off that it takes a long time to install the package.
yarn add @react-icons/all-files
# or
npm install @react-icons/all-files --save
example usage
import { FaBeer } from "@react-icons/all-files/fa/FaBeer";
function Question() {
return (
<h3>
Lets go for a <FaBeer />?
</h3>
);
}
You can add more icons by submitting pull requests or creating issues.
You can configure react-icons props using React Context API.
Requires React 16.3 or higher.
import { IconContext } from "react-icons";
<IconContext.Provider value={{ color: "blue", className: "global-class-name" }}>
<div>
<FaFolder />
</div>
</IconContext.Provider>;
| Key | Default | Notes |
|---|---|---|
color | undefined (inherit) | |
size | 1em | |
className | undefined | |
style | undefined | Can overwrite size and color |
attr | undefined | Overwritten by other attributes |
title | undefined | Icon description for accessibility |
Import path has changed. You need to rewrite from the old style.
// OLD IMPORT STYLE
import FaBeer from "react-icons/lib/fa/beer";
function Question() {
return (
<h3>
Lets go for a <FaBeer />?
</h3>
);
}
// NEW IMPORT STYLE
import { FaBeer } from "react-icons/fa";
function Question() {
return (
<h3>
Lets go for a <FaBeer />?
</h3>
);
}
Ending up with a large JS bundle? Check out this issue.
From version 3, vertical-align: middle is not automatically given. Please use IconContext to specify className or specify an inline style.
<IconContext.Provider value={{ style: { verticalAlign: 'middle' } }}>
className StylingComponent
<IconContext.Provider value={{ className: 'react-icons' }}>
CSS
.react-icons {
vertical-align: middle;
}
Dependencies on @types/react-icons can be deleted.
yarn remove @types/react-icons
npm remove @types/react-icons
./build-script.sh will build the whole project. See also CI scripts for more information.
yarn
cd packages/react-icons
yarn fetch # fetch icon sources
yarn build
First, check the discussion to see if anyone would like to add an icon set.
https://github.com/react-icons/react-icons/discussions/categories/new-icon-set
The SVG files to be fetched are managed in this file. Edit this file and run yarn fetch && yarn check && yarn build.
https://github.com/react-icons/react-icons/blob/master/packages/react-icons/src/icons/index.ts
Note The project is not actively accepting PR for the preview site at this time.
The preview site is the react-icons website, built in Astro+React.
cd packages/react-icons
yarn fetch
yarn build
cd ../preview-astro
yarn start
The demo is a Create React App boilerplate with react-icons added as a dependency for easy testing.
cd packages/react-icons
yarn fetch
yarn build
cd ../demo
yarn start
SVG is supported by all major browsers. With react-icons, you can serve only the needed icons instead of one big font file to the users, helping you to recognize which icons are used in your project.
MIT