import React, { useEffect, useState } from "react"; import axios from "axios"; export default function Nifty50Dashboard() { const [stocks, setStocks] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { fetchData(); const interval = setInterval(fetchData, 60000); // Refresh every 60s return () => clearInterval(interval); }, []); const fetchData = async () => { try { const response = await axios.get("http://localhost:5000/api/nifty50"); setStocks(response.data); setLoading(false); } catch (error) { console.error("Error fetching stock data", error); } }; if (loading) return
Symbol | Current Price | Change (%) | Volume | Market Cap |
---|---|---|---|---|
{stock.symbol} | ₹{stock.price.toFixed(2)} | = 0 ? "text-green-600" : "text-red-600"}`}> {stock.change.toFixed(2)}% | {stock.volume.toLocaleString()} | ₹{(stock.marketCap / 1e9).toFixed(2)} B |