Cat logomenu

Async Data-Fetching Sandbox

I recently needed to mock a very basic generic asynchronous data-fetching API with loading state in order to create a GitHub issue. I have a feeling it’ll be useful later, possibly even to other people, so here it is:

It uses a promisified wrapper around localStorage, with timeouts to simulate the async data-fetching, and local React state for loading, because my original use case for it was simulating a common pattern with the Apollo client. (But this should work for other kinds of async data-fetching.) It doesn’t really do much out of the box other than render a stringified version of the original data; even the data-update handler is commented out. Wire up however makes sense for you.

Give us a share!