loading...

re: Simplify JavaScript Promises VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Hi Sunny, very interesting article. Thanks! I especially loved this one-liner: const data = await fetch('/api').then(res => res.json()); ...
 

Definitely more concise!

I think there is something to be said about how a .then reads a bit better, but this can be argued both ways. Either example takes advantage of the language to do one thing: fetch data.

In most scenarios, you would have a helper function anyway, which is essentially what you wrote (I would just rename it to something like fetchUsers()).

code of conduct - report abuse