I am getting Binance coin data from Binance npm package. But when I try to run filter or map function it gives the error: TypeError: Cannot read properties of undefined (reading 'filter')
The code:
const client = Binance();
const [dataLoading, setDataLoaded] = useState(true);
const [tradesData, setTradesData] = useState();
const [length, setLength] = useState();
const tradesDataSet = async () => {
setTradesData(await client.trades({ symbol: "BTCUSDT" }));
setDataLoaded(false);
};
useEffect(() => {
tradesDataSet();
}, []);
console.log(
tradesData.filter((trade) => trade.price * trade.qty > 3000).length
);
How do I troubleshoot?