◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。
加密货币如今风靡一时,随着可用硬币的数量过多,有一个工具可以轻松搜索和查看它们的详细信息是至关重要的。 crypto finder 应用程序就是这样做的。该应用程序使用 react 构建,为用户搜索、过滤和查看加密货币详细信息提供无缝体验。
crypto finder 应用程序包括:
以下是项目结构的快速概述:
要开始使用 crypto finder 应用程序,请按照以下步骤操作:
git clone https://github.com/abhishekgurjar-in/crypto-finder cd crypto-finder
npm install
npm start
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 ( <div> <navbar></navbar><routes><route path="/" element="{<cryptofinder/">}/> <route path="/details/:id" element="{<cryptodetails/">}/> </route></route></routes><footer></footer> </div> ); }; export default app;
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 ( <div classname="loader-box"> <div classname="loader"></div> </div> ); } return ( <div classname="crypto-finder"> <div classname="input-box"> <input type="text" value="{search}" onchange="{(e)"> setsearch(e.target.value)} onkeydown={handlesearch} placeholder="search for a cryptocurrency" /> <button onclick="{handlesearch}">search</button> </div> <div classname="cards"> {filteredcrypto.map((val, id) => ( <div classname="card" key="{id}"> @@##@@ <h1>{val.name}</h1> <h4>{val.symbol.touppercase()}</h4> <h4>₹{val.current_price.tofixed(2)}</h4> <link to="{`/details/${val.id}`}"> <button>view details</button> </div> ))} </div> </div> ); }; 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 ( <div classname="loader-box"> <div classname="loader"></div> </div> ); } return ( <div classname="crypto-details"> <div classname="basic-details-image-box"> <div classname="basic-details"> <h1>{cryptodetails.name}</h1> <h4>{cryptodetails.symbol.touppercase()}</h4> <h4> current price: ₹ {cryptodetails.market_data.current_price.inr.tofixed(2)} </h4> </div> <div classname="image-box"> @@##@@ </div> </div> <div classname="detail-desc"> <h3>description :</h3> <p>{cryptodetails.description.en}</p> </div> <div classname="market-and-additional"> <div classname="market-data"> <h2>market data</h2> <p> <b>market cap: </b>₹ {cryptodetails.market_data.market_cap.inr.tolocalestring()} </p> <p> <b>total volume: </b>₹ {cryptodetails.market_data.total_volume.inr.tolocalestring()} </p> <p><b>24h high:</b> ₹{cryptodetails.market_data.high_24h.inr}</p> <p><b>24h low:</b> ₹{cryptodetails.market_data.low_24h.inr}</p> <p> <b> price change (24h):</b> ₹ {cryptodetails.market_data.price_change_24h.tofixed(2)} </p> <p> <b>price change percentage (24h):</b>{" "} {cryptodetails.market_data.price_change_percentage_24h.tofixed(2)}% </p> </div> <div classname="additional-info"> <h2>additional information</h2> <p><b>genesis date:</b> {cryptodetails.genesis_date || "n/a"}</p> <p> <b>homepage:</b>{" "} <a href="%7Bcryptodetails.links.homepage%5B0%5D%7D" target="_blank" rel="noopener noreferrer"> {cryptodetails.links.homepage[0]} </a> </p> <p> <b> blockchain site:</b>{" "} <a href="%7Bcryptodetails.links.blockchain_site%5B0%5D%7D" target="_blank" rel="noopener noreferrer"> {cryptodetails.links.blockchain_site[0]} </a> </p> </div> </div> </div> ); }; export default cryptodetails;
navbar.js 组件为应用程序提供标题。
import react from 'react' const navbar = () => { return ( <div classname="navbar"> <h1>crypto finder</h1> </div> ) } export default navbar
footer.js 组件为应用程序提供页脚。
import React from 'react' const Footer = () => { return ( <div classname="footer"> <p>Made with ❤️ by Abhishek Gurjar</p> </div> ) } export default Footer
您可以在此处查看 crypto finder 应用程序的实时演示。
构建 crypto finder 应用程序是一次有趣且具有教育意义的体验。它演示了如何使用 react 来获取和显示数据、处理路由以及创建响应式且用户友好的界面。我希望这个项目对您有所帮助,并激励您使用 react 创建自己的应用程序!
阿布舍克·古贾尔
您可以根据您的喜好或您可能已实现的其他功能随意调整或添加更多详细信息。
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。