#yyds干货盘点 react笔记之引入FontAwesome

时间:2021-07-14 00:38:09

前言

我是歌谣 我有个兄弟 巅峰的时候排名c站总榜19 叫前端小歌谣 曾经我花了三年的时间创作了他 现在我要用五年的时间超越他 今天又是接近兄弟的一天人生难免坎坷 大不了从头再来 歌谣的意志是永恒的 放弃很容易 但是坚持一定很酷 微信公众号前端小歌谣

#yyds干货盘点 react笔记之引入FontAwesome

总结

/*
* 引入FontAwesome
* - 安装依赖
* npm i --save @fortawesome/fontawesome-svg-core
npm i --save @fortawesome/free-solid-svg-icons
npm i --save @fortawesome/free-regular-svg-icons
npm i --save @fortawesome/react-fontawesome@latest

yarn add @fortawesome/react-fontawesome@latest @fortawesome/free-regular-svg-icons @fortawesome/fontawesome-svg-core @fortawesome/free-solid-svg-icons

- 引入组件
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
- 引入图标
import {faPlus} from "@fortawesome/free-solid-svg-icons";
- 使用组件
<FontAwesomeIcon icon={faPlus}/>
*
* */

counter.js

import React from 'react';
import classes from './Counter.module.css';
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
import {faPlus, faMinus} from "@fortawesome/free-solid-svg-icons";

/*
* 引入FontAwesome
* - 安装依赖
* npm i --save @fortawesome/fontawesome-svg-core
npm i --save @fortawesome/free-solid-svg-icons
npm i --save @fortawesome/free-regular-svg-icons
npm i --save @fortawesome/react-fontawesome@latest

yarn add @fortawesome/react-fontawesome@latest @fortawesome/free-regular-svg-icons @fortawesome/fontawesome-svg-core @fortawesome/free-solid-svg-icons

- 引入组件
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
- 引入图标
import {faPlus} from "@fortawesome/free-solid-svg-icons";
- 使用组件
<FontAwesomeIcon icon={faPlus}/>
*
* */

// 计数器的组件
const Counter = (props) => {
return (
<div className={classes.Counter}>

{
(props.amount && props.amount !== 0) ? (
<>
<button className={classes.Sub}><FontAwesomeIcon icon={faMinus}/></button>
<span className={classes.count}>{props.amount}</span>
</>
) : null
}

<button className={classes.Add}>
<FontAwesomeIcon icon={faPlus}/>
</button>
</div>
);
};

export default Counter;

我是歌谣 放弃很容易 坚持一定很酷 微信公众号前端小歌谣