AgentSkillsCN

react-icons

在React/Next.js中使用react-icons添加SVG图标。当您需要添加图标、选择图标集,或从react-icons(如Fa*、Hi*、Lu*、Md*等)中导入图标时,可选用此技能。本技能涵盖安装方法、导入路径,以及图标前缀的设定。

SKILL.md
--- frontmatter
name: react-icons
description: Use react-icons to add SVG icons in React/Next.js. Use when adding icons, choosing icon sets, or importing from react-icons (Fa*, Hi*, Lu*, Md*, etc.). Covers installation, import paths, and set prefixes.

React Icons

Include popular icon sets in React via ES imports; only the icons you use are bundled.

Installation

bash
pnpm add react-icons

Import pattern

Import from react-icons/{set}. Icon names are PascalCase.

tsx
import { FaBeer } from "react-icons/fa";
import { HiOutlineUser } from "react-icons/hi2";
import { LuChevronRight } from "react-icons/lu";

export function Example() {
  return (
    <>
      <FaBeer />
      <HiOutlineUser className="size-5" />
      <LuChevronRight aria-hidden />
    </>
  );
}

Icon set prefixes (import path)

SetPathExample
Font Awesome 5react-icons/faFaBeer, FaUser
Font Awesome 6react-icons/fa6Fa6Beer
Heroiconsreact-icons/hiHiUser
Heroicons 2react-icons/hi2HiOutlineUser, HiSolidUser
Lucidereact-icons/luLuChevronRight, LuHome
Material Designreact-icons/mdMdSettings
Bootstrapreact-icons/bsBsHouse
Radixreact-icons/rxRxAvatar
Phosphorreact-icons/piPiCaretRight
Remix Iconreact-icons/riRiAddLine
Tablerreact-icons/tbTbUser
Featherreact-icons/fiFiUser
Simple Icons (brands)react-icons/siSiGithub, SiVercel

Usage in this project

  • Next.js / React: Use as components; they render inline SVG.
  • Styling: Pass className (e.g. Tailwind size-5, text-muted-foreground) or style. Default size is 1em.
  • A11y: For decorative icons, add aria-hidden="true". For meaningful icons, pair with visible text or use aria-label on a wrapper.

Finding icon names

Large projects (optional)

For very large apps (e.g. Gatsby) where install time matters:

bash
pnpm add @react-icons/all-files
tsx
import { FaBeer } from "@react-icons/all-files/fa/FaBeer";

Prefer the default react-icons package unless bundle/install size is an issue.