
介绍
加密货币如今风靡一时,随着可用硬币的数量过多,有一个工具可以轻松搜索和查看它们的详细信息是至关重要的。 crypto finder 应用程序就是这样做的。该应用程序使用 react 构建,为用户搜索、过滤和查看加密货币详细信息提供无缝体验。
项目概况
crypto finder 应用程序包括:
- 搜索界面:用户可以按名称搜索加密货币。
- 加密货币列表:以卡片形式显示,显示基本信息。
- 详细视图:单击加密货币卡可显示有关该货币的更多详细信息。
特征
- 搜索功能:按名称过滤加密货币。
- 动态路由:查看所选加密货币的详细信息。
- 响应式设计:确保应用程序在不同的屏幕尺寸上看起来都不错。
- 加载指示器:在获取数据时显示加载器。
使用的技术
- react:用于构建用户界面。
- axios:用于发出 http 请求。
- react router:用于路由和导航。
- coingecko api:用于获取加密货币数据。
项目结构
以下是项目结构的快速概述:
-
源代码/
- 组件/
- cryptofinder.js
- cryptodetails.js
- navbar.js
- 页脚.js
- app.js
- app.css
安装
要开始使用 crypto finder 应用程序,请按照以下步骤操作:
- 克隆存储库
git clone https://github.com/abhishekgurjar-in/crypto-finder cd crypto-finder
- 安装依赖项
npm install
- 启动开发服务器
npm start
- 打开浏览器并导航到 http://localhost:3000 以查看正在运行的应用程序。
用法
- 搜索加密货币:在搜索框中输入内容并单击“搜索”以过滤加密货币列表。
- 查看详细信息:点击加密货币卡可查看详细信息。
代码说明
应用程序组件
app.js 组件设置路由并包含导航栏和页脚组件。
import react from "react";
import cryptofinder from "./components/cryptofinder";
import "./app.css";
import navbar from "./components/navbar";
import footer from "./components/footer";
import {route,routes} from "react-router-dom"
import cryptodetails from "./components/cryptodetails";
const app = () => {
return (
}/>
}/>
);
};
export default app;
cryptofinder 组件
cryptofinder.js 组件处理获取和显示加密货币列表。它包括一个用于过滤结果的搜索栏。
import react, { useeffect, usestate } from "react";
import axios from "axios";
import { link } from "react-router-dom";
const cryptofinder = () => {
const [search, setsearch] = usestate("");
const [crypto, setcrypto] = usestate([]);
const [filteredcrypto, setfilteredcrypto] = usestate([]);
useeffect(() => {
axios
.get(`https://api.coingecko.com/api/v3/coins/markets`, {
params: {
vs_currency: "inr",
order: "market_cap_desc",
per_page: 100,
page: 1,
sparkline: false,
},
})
.then((res) => {
setcrypto(res.data);
setfilteredcrypto(res.data);
});
}, []);
const handlesearch = () => {
const filtereddata = crypto.filter((data) => {
return data.name.tolowercase().includes(search.tolowercase());
});
setfilteredcrypto(filtereddata);
};
if (crypto.length === 0) {
return (
);
}
return (
setsearch(e.target.value)}
onkeydown={handlesearch}
placeholder="search for a cryptocurrency"
/>
{filteredcrypto.map((val, id) => (
@@##@@
{val.name}
{val.symbol.touppercase()}
₹{val.current_price.tofixed(2)}
))}
);
};
export default cryptofinder;
加密细节组件
cryptodetails.js 组件获取并显示有关所选加密货币的详细信息。
import react, { useeffect, usestate } from "react";
import axios from "axios";
import { useparams } from "react-router-dom";
const cryptodetails = () => {
const { id } = useparams();
const [cryptodetails, setcryptodetails] = usestate(null);
useeffect(() => {
axios
.get(`https://api.coingecko.com/api/v3/coins/${id}`, {
params: {
localization: false,
},
})
.then((res) => {
setcryptodetails(res.data);
});
}, [id]);
if (!cryptodetails) {
return (
);
}
return (
{cryptodetails.name}
{cryptodetails.symbol.touppercase()}
current price: ₹
{cryptodetails.market_data.current_price.inr.tofixed(2)}
@@##@@
description :
{cryptodetails.description.en}
market data
market cap: ₹
{cryptodetails.market_data.market_cap.inr.tolocalestring()}
total volume: ₹
{cryptodetails.market_data.total_volume.inr.tolocalestring()}
24h high: ₹{cryptodetails.market_data.high_24h.inr}
24h low: ₹{cryptodetails.market_data.low_24h.inr}
ECTouch移动商城系统
ECTouch是上海商创网络科技有限公司推出的一套基于 PHP 和 MySQL 数据库构建的开源且易于使用的移动商城网店系统!应用于各种服务器平台的高效、快速和易于管理的网店解决方案,采用稳定的MVC框架开发,完美对接ecshop系统与模板堂众多模板,为中小企业提供最佳的移动电商解决方案。ECTouch程序源代码完全无加密。安装时只需将已集成的文件夹放进指定位置,通过浏览器访问一键安装,无需对已有
下载
price change (24h): ₹
{cryptodetails.market_data.price_change_24h.tofixed(2)}
price change percentage (24h):{" "}
{cryptodetails.market_data.price_change_percentage_24h.tofixed(2)}%
additional information
genesis date: {cryptodetails.genesis_date || "n/a"}
homepage:{" "}
{cryptodetails.links.homepage[0]}
blockchain site:{" "}
{cryptodetails.links.blockchain_site[0]}
);
};
export default cryptodetails;
导航栏组件
navbar.js 组件为应用程序提供标题。
import react from 'react'
const navbar = () => {
return (
crypto finder
)
}
export default navbar
页脚组件
footer.js 组件为应用程序提供页脚。
import React from 'react'
const Footer = () => {
return (
Made with ❤️ by Abhishek Gurjar
)
}
export default Footer
现场演示
您可以在此处查看 crypto finder 应用程序的实时演示。
结论
构建 crypto finder 应用程序是一次有趣且具有教育意义的体验。它演示了如何使用 react 来获取和显示数据、处理路由以及创建响应式且用户友好的界面。我希望这个项目对您有所帮助,并激励您使用 react 创建自己的应用程序!
制作人员
- react 文档:react 文档
- coingecko api:coingecko
- axios 文档:axios 文档
作者
阿布舍克·古贾尔
您可以根据您的喜好或您可能已实现的其他功能随意调整或添加更多详细信息。









