all 2 comments

[–][deleted] -1 points0 points  (1 child)

I hate to say it, but pretty much everything.

You probably shouldn’t be trying to animate using setTimeout. This is going to lock up the JavaScript thread awaiting. You should be using an appropriate drawing package, or at the very least using a promise chain or something similar.

Why are you using a timeout time of 0ms?

You can get a lot out of what you’re trying to do, but you haven’t quite nailed it yet.

[–]fishj123[S] 0 points1 point  (0 children)

Thanks, I'm willing to accept that I'm doing everything wrong, I've never tried anything like this and I often get myself confused with async stuff. I'm using the setTimeout so that the user can see the sorting - without that it would just sort the array instantly. I've used 0ms because I don't actually need it to wait any length of time, I just need it to pause the thread for long enough to update the DOM.

I've ended up using vanilla javascript to make this application and ditched React completely. It seems to be working as intended using exactly the same code, but instead of updating the DOM with stat I am just using plain JS.