3 ms·
IMO React is missing hooks to work with promises. I made that hook myself but I think that promises along with AbortSignals (to interrupt promise if React decid
by vbezhenar 4y ago
IMO React is missing hooks to work with promises. I made that hook myself but I think that promises along with AbortSignals (to interrupt promise if React decided to cancel it) are basic JS API and React should just support them out of the box. I saw too much code which deals with async functions in useEffect in a buggy way. Things like ReactQuery are nice but they should not be required.
Here's my implementation, for the record: https://pastebin.com/rjj0FDDd https://pastebin.com/rjj0FDDd
- subleq 4y agoreact-query basically converts promises to hooks
- danabramov 4y agoWe agree. https://github.com/reactjs/rfcs/pull/229 https://github.com/reactjs/rfcs/pull/229
- selfmodruntime 4y agoYou probably won‘t answer, but what do you think of the (imo uncalled for) wishful thinking that react should‘ve stayed in the direction of Class components?
- sophiebits 4y agoDan wrote an answer today about classes here: https://news.ycombinator.com/item?id=35188669 https://news.ycombinator.com/item?id=35188669
- idkwhoiam 4y ago> Here's my implementation, for the record: https://pastebin.com/rjj0FDDd https://pastebin.com/rjj0FDDd This implementation doesn't account for the fact that the promise may settle after the component has been unmounted.
- fireant 4y agoMissing standard downstream promise cancellation is arguably one of the bigger problems in the whole javascript ecosystem. In C# almost every async function has a CancellationToken parameter, same in Go with Context. Even after years of writing fullstack javascript this is my first time seeing AbortSignals, probably because nobody uses them. Some libraries, like Axios, handroll their own cancellation mechanisms, but that does not really cut it.