react-icons vs react-feather
React 图标库选型对比:react-feather 与 react-icons
react-iconsreact-feather類似套件:

React 图标库选型对比:react-feather 与 react-icons

react-feather 和 react-icons 都是为 React 应用提供矢量图标的流行 npm 包,但它们在图标来源、API 设计和使用方式上有显著差异。react-feather 专注于 Feather Icons 这一单一图标集,提供简洁一致的 API;而 react-icons 是一个聚合型图标库,整合了包括 Feather、FontAwesome、Material Design 等数十个主流图标集,通过统一的导入方式暴露所有图标。两者都支持按需引入、自定义样式(如颜色、大小)和 TypeScript 类型支持,适用于需要在 React 组件中嵌入 SVG 图标的各类项目。

npm下載趨勢

3 年

GitHub Stars 排名

統計詳情

套件
下載數
Stars
大小
Issues
發布時間
許可
react-icons11,823,55412,69188.3 MB2464 個月前MIT
react-feather568,7551,9481 MB39-MIT

React 图标库深度对比:react-feather 与 react-icons

在 React 项目中引入图标看似简单,但选型不当可能导致 bundle 体积膨胀、维护成本上升或设计一致性受损。react-feather 和 react-icons 是两个主流选择,但它们的设计哲学和适用场景截然不同。本文从工程实践角度,深入剖析两者的异同。

📦 图标来源与覆盖范围

react-feather 仅包含 Feather Icons 这一开源图标集。Feather 以 24×24 像素、单色、线条风格著称,共 280+ 个图标,风格高度统一,适合追求极简美学的界面。

// react-feather:仅限 Feather 图标
import { Heart, User, Settings } from 'react-feather';

function App() {
  return (
    <div>
      <Heart color="red" />
      <User size={20} />
      <Settings />
    </div>
  );
}

react-icons 则是一个“图标超市”,聚合了包括 Feather、FontAwesome、Material Design、Ionicons 等 30+ 个 主流图标库。每个图标集通过独立的命名空间导出,例如 Feather 图标位于 Fi 前缀下。

// react-icons:多图标集混合使用
import { FiHeart, FaUser, MdSettings } from 'react-icons';

function App() {
  return (
    <div>
      <FiHeart color="red" />
      <FaUser size={20} />
      <MdSettings />
    </div>
  );
}

💡 关键区别:react-feather 是“专卖店”,react-icons 是“百货商场”。前者专注单一风格,后者提供广泛选择。

⚙️ API 与使用方式

两者都基于 React 组件封装 SVG,支持通过 props 自定义 size、color、className 等属性,但命名约定不同。

react-feather 的组件名直接对应图标名(PascalCase),无前缀:

import { Activity, CloudRain } from 'react-feather';

<Activity size={24} color="#000" />
<CloudRain className="custom-icon" />

react-icons 为每个图标集分配固定前缀(如 Feather 为 Fi,FontAwesome 为 Fa),组件名也采用 PascalCase:

import { FiActivity, FiCloudRain } from 'react-icons/fi'; // 注意:需指定子路径

<FiActivity size={24} color="#000" />
<FiCloudRain className="custom-icon" />

⚠️ 注意:react-icons 要求从具体子路径导入(如 react-icons/fi),否则会引入整个库,导致 bundle 体积剧增。这是新手常犯的错误。

📦 Bundle Size 与 Tree Shaking

两者均支持 按需引入(tree-shaking),但实际效果取决于使用方式。

  • react-feather:由于只包含一个图标集,即使错误地全量导入(import * as Feather from 'react-feather'),最大体积也有限(约 50KB minified)。正确按需引入后,每个图标仅增加 ~150 字节。

  • react-icons:若从根路径导入(import { FiHeart } from 'react-icons'),Webpack 可能无法有效 tree-shake,导致整个 Feather 图标集(甚至更多)被打包。必须从子路径导入(import { FiHeart } from 'react-icons/fi')才能确保只包含所需图标。

// ✅ 正确:react-icons 按需引入
import { FiHeart } from 'react-icons/fi'; // 仅包含 Heart 图标

// ❌ 错误:可能引入整个 Feather 图标集
import { FiHeart } from 'react-icons';

🎨 样式定制能力

两者在样式定制上能力相当,均通过 props 控制 SVG 属性:

属性作用示例值
size设置图标宽高24, '1.5em', '2rem'
color设置填充/描边颜色'#ff0000', 'currentColor'
className添加 CSS 类'icon-primary'
style内联样式{ opacity: 0.8 }
// 两者均支持以下写法
<Icon size={32} color="blue" className="hover-effect" style={{ marginRight: '8px' }} />

💡 提示:推荐使用 color="currentColor" 配合父元素文本颜色,实现自动主题适配。

🔧 TypeScript 支持

两者均提供完整的 TypeScript 类型定义,组件 props 类型明确:

// react-feather 类型示意
interface IconProps extends React.SVGProps<SVGSVGElement> {
  size?: string | number;
  color?: string;
}

// react-icons 类型类似,额外继承 SVGProps

开发者可获得良好的 IDE 自动补全和类型检查,无需额外配置。

🛠️ 工程实践建议

场景 1:设计系统已锁定 Feather 风格

  • 推荐 react-feather:API 更简洁,无多余依赖,bundle 更可控。
  • 避免引入 react-icons 造成间接依赖膨胀。

场景 2:需要混合使用多种图标集

  • 必须选 react-icons:react-feather 无法满足需求。
  • 严格遵守子路径导入规则,并在 CI 中加入 bundle 分析(如 webpack-bundle-analyzer)防止意外全量引入。

场景 3:对 bundle size 极度敏感(如微前端子应用)

  • 若仅需少量图标,可考虑直接内联 SVG 代码,彻底消除依赖。
  • 否则优先 react-feather(单一图标集上限低)。

📊 总结:核心差异速查表

维度react-featherreact-icons
图标来源仅 Feather Icons30+ 图标集(含 Feather、FA、MD 等)
导入方式import { Icon } from 'react-feather'import { FiIcon } from 'react-icons/fi'
Bundle 风险低(单一集上限固定)高(错误导入会引入整个图标集)
适用场景单一风格、轻量项目多风格混合、大型应用
学习成本极低需记忆各图标集前缀(如 Fi, Fa, Md)

💡 最终建议

  • 不要为了“未来可能用其他图标”而提前选择 react-icons。YAGNI(You Aren't Gonna Need It)原则在此适用——先用 react-feather,等真有需求再迁移。
  • 如果已在用 react-icons,务必审计导入路径。运行 npm ls react-icons 并检查打包报告,确保没有意外全量引入。
  • 图标一致性比数量更重要。混合多种图标风格易导致 UI 碎片化,优先在设计层面统一图标语言,再选技术方案。

无论选择哪个库,记住:图标是 UI 的细节,但细节决定专业度。

如何選擇: react-icons vs react-feather

  • react-icons:

    选择 react-icons 如果你需要灵活使用多个图标库(如同时用 Feather 和 Material Icons),或尚未确定最终图标方案。它通过统一的命名和导入方式简化了多图标集的管理,适合需要快速原型验证或支持多种设计语言的大型应用。

  • react-feather:

    选择 react-feather 如果你只需要 Feather Icons 这一套风格统一、轻量简洁的图标,并希望获得最直接的 API 体验。它适合对 bundle size 敏感、且设计系统已确定采用 Feather 风格的项目,避免引入不必要的图标集依赖。

react-icons 的 README

React Icons

React Icons

npm

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.

Installation (for standard modern project)

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';

Installation (for meteorjs, gatsbyjs, etc)

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>
  );
}

Icons

Icon LibraryLicenseVersionCount
Circum IconsMPL-2.0 license1.0.0288
Font Awesome 5CC BY 4.0 License5.15.4-3-gafecf2a1612
Font Awesome 6CC BY 4.0 License6.5.22045
Ionicons 4MIT4.6.3696
Ionicons 5MIT5.5.41332
Material Design iconsApache License Version 2.04.0.0-98-g9beae745bb4341
TypiconsCC BY-SA 3.02.1.2336
Github Octicons iconsMIT18.3.0264
FeatherMIT4.29.1287
LucideISCv5.1.0-6-g438f572e1215
Game IconsCC BY 3.012920d6565588f0512542a3cb0cdfd36a497f9104040
Weather IconsSIL OFL 1.12.0.12219
DeviconsMIT1.8.0192
Ant Design IconsMIT4.4.2831
Bootstrap IconsMIT1.11.32716
Remix IconApache License Version 2.04.2.02860
Flat Color IconsMIT1.0.2329
Grommet-IconsApache License Version 2.04.12.1635
HeroiconsMIT1.0.6460
Heroicons 2MIT2.1.3888
Simple IconsCC0 1.0 Universal12.14.03209
Simple Line IconsMIT2.5.5189
IcoMoon FreeCC BY 4.0 Licensed006795ede82361e1bac1ee76f215cf1dc51e4ca491
BoxIconsMIT2.1.41634
css.ggMIT2.1.1704
VS Code IconsCC BY 4.00.0.35461
Tabler IconsMIT3.2.05237
Themify IconsMITv0.1.2-2-g9600186352
Radix IconsMIT@radix-ui/react-[email protected]318
Phosphor IconsMIT2.1.19072
Icons8 Line AwesomeMIT1.3.11544

You can add more icons by submitting pull requests or creating issues.

Configuration

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>;
KeyDefaultNotes
colorundefined (inherit)
size1em
classNameundefined
styleundefinedCan overwrite size and color
attrundefinedOverwritten by other attributes
titleundefinedIcon description for accessibility

Migrating from version 2 -> 3

Change import style

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.

Adjustment CSS

From version 3, vertical-align: middle is not automatically given. Please use IconContext to specify className or specify an inline style.

Global Inline Styling

<IconContext.Provider value={{ style: { verticalAlign: 'middle' } }}>

Global className Styling

Component

<IconContext.Provider value={{ className: 'react-icons' }}>

CSS

.react-icons {
  vertical-align: middle;
}

TypeScript native support

Dependencies on @types/react-icons can be deleted.

Yarn

yarn remove @types/react-icons

NPM

npm remove @types/react-icons

Contributing

./build-script.sh will build the whole project. See also CI scripts for more information.

Development

yarn
cd packages/react-icons
yarn fetch  # fetch icon sources
yarn build

Add/Update icon set

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

Preview

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

Demo

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

Why React SVG components instead of fonts?

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.

Related Projects

Licence

MIT

  • Icons are taken from the other projects so please check each project licences accordingly.