Reputation: 39
I want to make a nextjs page where a user can view the payment status of a specific transaction on the Ethereum blockchain. How do I loop this function every few seconds to check if the transaction status changed and change the UI?
Upvotes: 1
Views: 3377
Reputation: 69
Have you considered using setTimeout?
const timer = setTimeout(() => {
someFunction()
}, 1000);
The second parameter is the timeout time between calls in ms. When your component unmounts make sure to clear the timeout by calling clearTimeout in your unmount or function returned by useEffect
clearTimeout(timer)
More info can be found in the docs here: https://developer.mozilla.org/en-US/docs/Web/API/setTimeout
Upvotes: 2