Is there other ways to animate an object moving in a canvas without the use of setInterval() or setTimeout()?
Reason is because it kinda lags as time goes by when using useInterval(). I got no idea why it lags also.
I tried removing the setInerval() and everything is ok with no lag but there is no animation.
Yes. There is also requestAnimationFrame, but not on all browsers.
Additionally, try setting your interval to much smaller and much larger values and see if either make it less jumpy.
Additionally, make sure there is as little going on in your draw loop. It could be your own fault for the lag. Canvas is pretty sensitive to performance things, and its up to you to keep it running fast.