Sitemap
ITNEXT

ITNEXT is a platform for IT developers & software engineers to share knowledge, connect, collaborate, learn and experience next-gen technologies.

useFetch: React custom hook for Fetch API with Suspense and Concurrent Mode in Mind

5 min readFeb 3, 2019

--

Until we have react-cache or for a different purpose.

Press enter or click to view image in full size

Introduction

While I don’t feel like coding React without hooks, react-cache still seems to be still far away. Surely, caching in data fetching important, nevertheless I would like to seek possibilities of implementations only with React Hooks. These might be obsoleted in the future, but I want something today, that is “useFetch”. This could be still useful without react-cache in case sophisticated caching is not necessary.

I’ve started developing “useFetch” as a tutorial to build a custom hook.

Since then, the support for AbortController is added, which is incredible if you are fetching one-time-only data like typeahead suggest.

Now, to make this “useFetch” hook more usable, this article describes about supporting Suspense and also Concurrent React a bit.

React Suspense

--

--

ITNEXT
ITNEXT

Published in ITNEXT

ITNEXT is a platform for IT developers & software engineers to share knowledge, connect, collaborate, learn and experience next-gen technologies.