react-icons vs react-feather vs feather-icons-react
React 项目中 Feather 图标库的技术选型与架构对比
react-iconsreact-featherfeather-icons-react类似的npm包:

React 项目中 Feather 图标库的技术选型与架构对比

feather-icons-react、react-feather 和 react-icons 都是在 React 应用中使用 Feather 图标集的常见方案,但它们的实现原理和适用场景各不相同。react-feather 是专为 Feather 设计的独立库,提供独立的 SVG 组件;react-icons 是一个聚合库,包含 Feather 在内的数千种图标,支持统一的导入方式;feather-icons-react 通常是对原始 JavaScript 库的封装,可能涉及 DOM 操作。理解它们在渲染机制、打包体积优化和 API 设计上的差异,对于构建高性能、可维护的前端应用至关重要。

npm下载趋势

3 年

GitHub Stars 排名

统计详情

npm包名称
下载量
Stars
大小
Issues
发布时间
License
react-icons5,081,34812,68088.3 MB2444 个月前MIT
react-feather213,5871,9481 MB39-MIT
feather-icons-react16,51748498 kB31 年前ISC

React 图标库方案深度对比:feather-icons-react vs react-feather vs react-icons

在 React 生态中,图标不仅仅是图片,它们是组件。选择正确的图标库直接影响应用的加载速度、服务端渲染(SSR)兼容性以及代码的可维护性。feather-icons-react、react-feather 和 react-icons 都提供了 Feather 图标,但底层实现逻辑差异巨大。本文将从架构师视角,深入分析这三者的技术细节。

🧩 导入方式:独立组件 vs 动态名称 vs 统一聚合

图标的导入方式决定了代码的静态分析能力和打包优化空间。

react-feather 为每个图标导出一个独立的 React 组件。

  • 你必须知道具体图标名称才能导入。
  • 有利于构建工具进行静态分析。
// react-feather: 独立组件导入
import { User, Home, Settings } from 'react-feather';

function Nav() {
  return (
    <div>
      <User />
      <Home />
      <Settings />
    </div>
  );
}

react-icons 同样导出独立组件,但带有前缀以区分图标集。

  • Feather 图标使用前缀 Fi。
  • 适合多图标集混合管理。
// react-icons: 带前缀的独立组件
import { FiUser, FiHome, FiSettings } from 'react-icons/fi';

function Nav() {
  return (
    <div>
      <FiUser />
      <FiHome />
      <FiSettings />
    </div>
  );
}

feather-icons-react 通常导出一个通用组件,通过 name 属性指定图标。

  • 支持动态字符串加载。
  • 但可能阻碍 Tree Shaking,因为构建工具无法静态分析字符串。
// feather-icons-react: 动态名称导入
import { Icon } from 'feather-icons-react';

function Nav() {
  const icons = ['user', 'home', 'settings'];
  return (
    <div>
      {icons.map(name => <Icon key={name} name={name} />)}
    </div>
  );
}

🖥️ 渲染机制:纯 SVG 组件 vs DOM 操作

这是三者最核心的架构差异,直接影响 SSR 和 hydration。

react-feather 和 react-icons 都是纯 SVG 组件。

  • 图标直接渲染为 <svg> 标签。
  • 完全符合 React 声明式理念,无副作用。
  • 服务端渲染(SSR)友好,HTML 输出一致。
// react-feather / react-icons 渲染输出原理
// 直接返回 SVG 元素,无 DOM 操作
function UserIcon() {
  return (
    <svg viewBox="0 0 24 24" ...>
      <path d="..." />
    </svg>
  );
}

feather-icons-react 部分版本依赖原始 feather-icons JS 库。

  • 原始库使用 feather.replace() 操作 DOM。
  • 需要在 useEffect 中触发,导致客户端 hydration 不匹配。
  • 在 SSR 项目中可能导致页面加载时图标闪烁或丢失。
// feather-icons-react (潜在实现风险)
// 依赖 useEffect 进行 DOM 替换
useEffect(() => {
  feather.replace(); // 直接操作 DOM,非 React 方式
}, []);

// 初始渲染可能是 <i data-feather="user"></i>,随后被 JS 替换

📦 打包优化:Tree Shaking 支持

现代前端构建工具(如 Webpack、Vite)依赖静态结构来移除未使用的代码。

react-feather 支持完美的 Tree Shaking。

  • 只导入使用的图标,未使用的会被移除。
  • 打包体积与使用图标数量成正比。
// react-feather: 仅打包 User 组件
import { User } from 'react-feather';
// Home 和 Settings 不会被打包

react-icons 同样支持优秀的 Tree Shaking。

  • 需要精确导入路径(如 react-icons/fi)。
  • 如果导入整个库,体积会很大。
// react-icons: 正确做法
import { FiUser } from 'react-icons/fi';

// react-icons: 错误做法(避免)
// import * as Fi from 'react-icons/fi'; // 会打包所有图标

feather-icons-react 的 Tree Shaking 取决于实现。

  • 如果使用动态 name 属性,构建工具无法判断哪些图标被使用。
  • 可能导致所有图标代码都被打包进最终文件。
// feather-icons-react: 动态名称风险
<Icon name={dynamicName} />
// 构建工具无法静态分析,可能保留全部图标数据

🎨 样式定制:Props 传递

三者都支持通过 Props 控制图标外观,但细节略有不同。

react-feather 支持标准 SVG 属性。

  • 使用 size、color 等 props。
  • 直接传递给底层 <svg> 元素。
// react-feather: 样式控制
<User size={24} color="#333" strokeWidth={2} />

react-icons 支持类似的属性,但属性名可能统一。

  • 使用 size、color。
  • 部分版本支持 className 直接应用 CSS 类。
// react-icons: 样式控制
<FiUser size={24} color="#333" className="custom-icon" />

feather-icons-react 依赖原始库的 API。

  • 通常支持 color、width、height。
  • 但可能不如纯 React 组件灵活。
// feather-icons-react: 样式控制
<Icon name="user" color="#333" width={24} height={24} />

🛠️ 维护状态与生态系统

库的活跃度决定了长期维护的安全性和 Bug 修复速度。

react-icons 拥有最活跃的社区。

  • 定期更新,支持最新 React 版本。
  • 包含数百个图标集,不仅仅限于 Feather。
  • 遇到问题容易找到解决方案。

react-feather 处于稳定维护状态。

  • 更新频率较低,但 API 稳定。
  • 专注于 Feather 单一集合,无多余依赖。
  • 适合长期不变的项目。

feather-icons-react 维护情况不一。

  • 存在多个同名或类似包,质量参差不齐。
  • 部分包已长时间未更新。
  • 建议在使用前仔细检查 GitHub 仓库活跃度。

📊 核心差异总结表

特性react-featherreact-iconsfeather-icons-react
组件形式独立 SVG 组件 (<User />)独立 SVG 组件 (<FiUser />)通用组件 (<Icon name="..." />)
渲染方式纯 React SVG纯 React SVG可能涉及 DOM 操作
SSR 支持✅ 优秀✅ 优秀⚠️ 可能存在 Hydration 问题
Tree Shaking✅ 支持✅ 支持⚠️ 动态名称可能失效
图标范围仅 Feather数千种 (含 Feather)仅 Feather
社区活跃度🟡 稳定🟢 极高🔴 参差不齐

💡 架构师建议

react-icons 是现代 React 项目的默认首选 🏆。它提供了最佳的 Tree Shaking 支持、活跃的维护和统一的 API,尤其适合需要多种图标集或长期维护的企业级应用。

react-feather 适合极简主义项目 🎯。如果你确定只使用 Feather 图标,且希望依赖树更干净,它是一个可靠的轻量级替代方案。

feather-icons-react 建议谨慎使用 ⚠️。除非你有特殊的动态加载需求且已验证 SSR 兼容性,否则纯 SVG 组件方案(前两者)在架构上更安全、更符合 React 最佳实践。

最终结论:在 90% 的场景下,选择 react-icons 能为你减少未来的技术债务。它平衡了性能、灵活性和维护成本,是架构决策中的稳健选择。

如何选择: react-icons vs react-feather vs feather-icons-react

  • react-icons:

    如果你的项目需要混合使用多种图标集(如 Material、FontAwesome 等),或者希望获得最活跃的社区维护和统一的 API 体验,这是最佳选择。它支持按需导入单个图标,Tree Shaking 效果优秀,是目前现代 React 架构中的主流方案。

  • react-feather:

    如果你只需要 Feather 图标集,且希望依赖包尽可能小,这是一个稳定且专一的选择。它提供独立的 SVG 组件,支持完整的 Tree Shaking,适合追求轻量级且图标需求单一的项目,但社区活跃度相对较低。

  • feather-icons-react:

    如果你的项目需要通过字符串动态加载图标名称,且不在意潜在的 SSR hydration 问题,可以考虑此方案。但需注意,部分版本依赖原始 JS 库进行 DOM 替换,这在 React 服务端渲染中可能导致界面闪烁或不一致,建议在生产环境谨慎评估。

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.