Загрузка видео...

Не удалось загрузить видео

На главную

You might be using `fetch` wrong...

411,223 просмотров • 3 лет назад •via X (Twitter)

Комментарии: 10

Фото профиля Steve (Builder.io)
Steve (Builder.io)3 лет назад

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

Фото профиля Steve (Builder.io)
Steve (Builder.io)3 лет назад

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

Фото профиля Germinal Camps
Germinal Camps3 лет назад

Or you could just use axios…

Фото профиля Steve (Builder.io)
Steve (Builder.io)3 лет назад

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

Фото профиля Tanguy Krotoff
Tanguy Krotoff3 лет назад

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();

Фото профиля Steve (Builder.io)
Steve (Builder.io)3 лет назад

Oo I like

Фото профиля Simon Vrachliotis
Simon Vrachliotis3 лет назад

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

Фото профиля Steve (Builder.io)
Steve (Builder.io)3 лет назад

Thanks Simon!

Фото профиля Steve (Builder.io)
Steve (Builder.io)3 лет назад

Wrote more on this in my latest blog post:

Фото профиля Franco Valdes
Franco Valdes3 лет назад

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.

Похожие видео