在我的React应用程序中,我收到“ library”(未定义no-undef)错误。我正在尝试在我的应用程序中添加很棒的字体。我为此编写了一些代码:
错误:
编译失败
./ src / sections / header / header.js
第11行:未定义“库” no-undef
搜索关键字以详细了解每个错误。
import React, { Component } from "react";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import {
faGoogle,
faFacebook,
faTwitter,
fainstagram
} from '@fortawesome/free-brands-svg-icons';
library.add(
faGoogle,
faFacebook,
faTwitter,
fainstagram
);
class Header extends Component {
render() {
return (
<div className="social-icons">
<ul>
<li><a href="javascript:void(0)" className="facebook"><FontAwesomeIcon icon="fafacebook" /></a></li>
<li><a href="javascript:void(0)" className="twitter"><FontAwesomeIcon icon="fatwitter" /></a></li>
<li><a href="javascript:void(0)" className="instagram"><FontAwesomeIcon icon="fainstagram" /></a></li>
</ul>
</div>
)
}
}
import React from 'react';
import logo from './logo.svg';
import './App.css';
import bootstrap from 'reactstrap';
import { library } from '@fortawesome/fontawesome-svg-core'
import { fab } from '@fortawesome/free-brands-svg-icons'
library.add(fab);
答案 0 :(得分:1)
您可以添加库导入,因为其他组件无法全局访问导入
import React, { Component } from "react";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { library } from '@fortawesome/fontawesome-svg-core'
import {
faGoogle,
faFacebook,
faTwitter,
fainstagram
} from '@fortawesome/free-brands-svg-icons';
library.add(
faGoogle,
faFacebook,
faTwitter,
fainstagram
);
class Header extends Component {
render() {
return (
<div className="social-icons">
<ul>
<li><a href="javascript:void(0)" className="facebook"><FontAwesomeIcon icon="fafacebook" /></a></li>
<li><a href="javascript:void(0)" className="twitter"><FontAwesomeIcon icon="fatwitter" /></a></li>
<li><a href="javascript:void(0)" className="instagram"><FontAwesomeIcon icon="fainstagram" /></a></li>
</ul>
</div>
)
}
}