[英]How to use weather-icons with React JS?
So I am trying to use weather-icons in a React application.所以我想在 React 应用程序中使用天气图标。
I downloaded the package and added it to my solution ( here ).我下载了package并将其添加到我的解决方案中( 此处)。
(I use react-redux-universal-hot-example starter kit) (我使用react-redux-universal-hot-example入门工具包)
In a Forecast.js container I added the following:在Forecast.js容器中,我添加了以下内容:
import React, {Component, PropTypes} from 'react'; import {connect} from 'react-redux'; import {fetchForecast} from 'redux/modules/weatherForecast'; @connect( state => ({forecast: state.weatherForecast.forecast}), {fetchForecast} ) export default class Forecast extends Component { render() { return ( <div> <i className="wi wi-day-sunny"></i> </div>); } }
It doesn't work yet...它还没有用...
My code structure:我的代码结构:
[src]
|--[containers]
| |--[Forecast]
| |--Forecast.js
|
|--[weather-icons]
|--[css]
|--[font]
|--[less]
|--[sass]
|--[values]
One way is importing the css file directly; 一种方法是直接导入css文件。 (As stated here )
(如前所述这里 )
import 'weather-icons/css/weather-icons.css';
Note: Path can be changed. 注意:路径可以更改。 I've installed the weather-icons package through npm which means it is under node_modules.
我已经通过npm安装了weather-icons软件包,这意味着它位于node_modules下。
And After importing the css file you can use it like below; 导入css文件后,您可以像下面这样使用它;
<i className="wi wi-day-lightning"></i>
[2023] [2023]
If someone is doing this is Next.js which does not allow to import global css, just use css modules!如果有人这样做是 Next.js 不允许导入全局 css,只需使用 css 模块!
import is from "../../styles/weather-icons.min.module.css"
And use it like this even with tailwind:D即使顺风也可以像这样使用它:D
<i className={`${is.wi} ${is["wi-day-cloudy"]} text-xl text-cyan-300`}></i>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.