DEV Community

Discussion on: React: "I really wish this is how I could write components."

Collapse
 
sebastienlorber profile image
Sebastien Lorber

Your code is subject to race conditions.

See dev.to/sebastienlorber/handling-ap...

You'd rather use a lib that solves it for you with all the edge cases, like github.com/slorber/react-async-hook

Collapse
 
joelnet profile image
JavaScript Joel

Yep this is correct! Any previous fetch needs to be aborted.

Since this code was just for fun, I don't think I'll be spending the time to add these cases into it. But if someone wants to contribute a gist, i'll gladly link it.

Cheers!