I am using the useApiContract function like this:
function ViewLottoCountDown() {
const { runContractFunction, data, error, isLoading, isFetching } =
useApiContract({
address: lottoAddress,
functionName: "LAST_PLAYER_AT",
chain: "mumbai",
abi: msLottoAbi,
params: {},
});
useEffect(() => {
if (account && !data && !isFetching) {
runContractFunction();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [account, data, isFetching]);
if (data) {
return JSON.stringify(data);
}
return;
}
I have multiple reads happening on page (10-20), and about 80% of the time the page takes a long time to load. Sometimes only half will load and the rest will take about a minute to show up. I’m thinking that there is a rate limit I must be breaking, the functions upon getting an error (400 error) will just try again without any breaks.
Within browser console all I get is
xhr.js:212 POST https://mdyoiqc6wp4m.usemoralis.com:2053/server/functions/runContractFunction 400
The above error is shown like 20+ times a second and causes lag on the website.
How do i add a break to the useEffect or make it so that the data isn’t requested so frequently?
Also another thing I have experienced with the way the code is set is that once the data is retrieved, it will never try to get fresh data until the page is refreshed. How could I for example grab data per second, when the user changes, or whenever it is updated in the smartContract?
Have seen Moralis server pinned at 100% cpu, and typically this is when I experience these 400 errors (Another reason I’m thinking rate limit).