Video wird geladen...

Video konnte nicht geladen werden

Zur Startseite

You might be using `fetch` wrong...

411,223 Aufrufe • vor 3 Jahren •via X (Twitter)

10 Kommentare

Profilbild von Steve (Builder.io)
Steve (Builder.io)vor 3 Jahren

If you are interested in wretch, the tiny wrapper around fetch, you can learn more about it here

Profilbild von Steve (Builder.io)
Steve (Builder.io)vor 3 Jahren

For a cool trick to make `fetch` more intuitive without using any libraries see pt 2 here:

Profilbild von Germinal Camps
Germinal Campsvor 3 Jahren

Or you could just use axios…

Profilbild von Steve (Builder.io)
Steve (Builder.io)vor 3 Jahren

True, though it is over 5x larger (11kb gzip vs 1.9kb gzip), so if perf is important for your site/app minimizing kb can be valuable

Profilbild von Tanguy Krotoff
Tanguy Krotoffvor 3 Jahren

I've written a small fetch wrapper (~250 lines) that does this. - Comes with test utilities - Supports Node.js & web browsers - Written in TypeScript - Fully tested const response = await postJSON(url, data).json();

Profilbild von Steve (Builder.io)
Steve (Builder.io)vor 3 Jahren

Oo I like

Profilbild von Simon Vrachliotis
Simon Vrachliotisvor 3 Jahren

The delivery on these tips is amazing, congrats! Love the karaoke-like transcript progress 👍

Profilbild von Steve (Builder.io)
Steve (Builder.io)vor 3 Jahren

Thanks Simon!

Profilbild von Steve (Builder.io)
Steve (Builder.io)vor 3 Jahren

Wrote more on this in my latest blog post:

Profilbild von Franco Valdes
Franco Valdesvor 3 Jahren

That was one of my biggest issues when fetch came out. I wish non 200 responses would automatically fall into the catch but they do not.

Ähnliche Videos