'Fetch json API real time
I want to update the dom for all the users, while fetching some datas from an API. This is for an NFT project and I want to update the number of NFTs left, so I'm using a timer, but I feel that the page is lagging a bit. How can I improve this? Thank you!
const controller = new AbortController();
const signal = controller.signal;
const fetchMintedNFTs = async () => {
const response = await fetch(mintedNFTs(smartContract), {signal});
const data = await response.json();
setalreadyMintedNFTs(data);
setLoadingMintedNFTs(false);
};
const interval = setInterval(() => fetchMintedNFTs(), 10000);
useEffect(() =>
{
},[fetchMintedNFTs(),interval]);
I'm fetching this https://devnet-api.elrond.com/nfts/count?creator=
Solution 1:[1]
i think use fetch with interval is not recomended in this case. i suggest use websocket instead. with websocket you can get data realtime and not need call the api with interval, because websocket connection is bidirectional
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | galih wisnuaji |
