So as a personal project of mine, I wanted to track all the WSB stonks. Unfortunately the api im using from alpha advantage has you making multiple requests for different symbols(Please correct me if I'm wrong). I was wondering if I can just use one state and map through them in one component, instead of having multiple states for each individual symbols and passing them through the same component multiple times. As you can see from my code below I'm trying to set my gmedata, amcdata, tesladata, and pltrdata to one variable called allstockdata then setStock(allstockData) but its a fail =(
import stockApi from "../apis/stockApi";
import cryptoApi from "../apis/cryptoApi";
const StonkList = () => {
const [cryptos, setCryptos] = useState([]);
const [stocks, setStocks] = useState([]);
const [gme, setGme] = useState([]);
const [amc, setAmc] = useState([]);
const [tesla, setTesla] = useState([]);
const [palantir, setPalantir] = useState([]);
const fetchData = async () => {
const cryptoData = await cryptoApi.get("/coins/markets/", {
params: {
vs_currency: "usd",
ids: "bitcoin, dogecoin",
},
});
const gmeData = await stockApi.get("", {
params: {
function: "TIME_SERIES_DAILY_ADJUSTED",
symbol: "GME",
apikey: "EZ8JMJUGE397BZEU",
},
});
const amcData = await stockApi.get("", {
params: {
function: "TIME_SERIES_DAILY_ADJUSTED",
symbol: "AMC",
apikey: "EZ8JMJUGE397BZEU",
},
});
const teslaData = await stockApi.get("", {
params: {
function: "TIME_SERIES_DAILY_ADJUSTED",
symbol: "TSLA",
apikey: "EZ8JMJUGE397BZEU",
},
});
const pltrData = await stockApi.get("", {
params: {
function: "TIME_SERIES_DAILY_ADJUSTED",
symbol: "GME",
apikey: "EZ8JMJUGE397BZEU",
},
});
const [gmeData, amcData, teslaData, pltrData] = allStockData;
setCryptos(cryptoData.data);
setStocks(allStockData.data);
console.log(cryptoData.data);
console.log(allStockData.data);
};
useEffect(() => {
fetchData();
}, []);
return <div></div>;
};
export default StonkList;