6
msdsk
1y

The entire react "return of a useEffect is its cleanup" is one of the most retarded design decisions ever. Hello, you can't have async functions. Do you want to return early and still have a cleanup? Good luck, hope you like debugging. Who the fuck came up with this idea and what was it inspired by.

Comments
  • 0
    Not sure it was better with the former lifecycle hooks. Seems like you can easily end up with memory leaks in React if you’re not careful.
    Haven’t touched React in a while though so I wouldn’t know at this point…
  • 0
    @black-kite
    Sure we need a way of explicitly state cleanup functions per-effect but it can be done the Vue way: by passing onCleanup as a parameter.
  • 0
    @msdsk why can't it be async? And, saying it could, what would you want the renderer to wait for? Couldn't you just fire and forget whatever you want cleaned up?

    Genuinely curious.
  • 0
    @spongessuck I mean not that you can't have async cleanup but you can't have simple async effects. They need to be wrapped in `const handle = async ()=>{}; handle()`, otherwise they return a promise and it's not a cleanup function.
Add Comment