Abstracting REST API calls with Query Component pattern

Being inspired by Apollo’s Query component and the way it is abstracting away all internals from presentation, I tried to adapt their solution to make it easier to make REST API calls.

In my example I will fetch for a GitHub user’s repos. Here is how Query component will look like:

1

And here is this query component usage:

2

Here is the codesandbox demo:
https://codesandbox.io/s/ko3wjqn4y3

Query component pattern is based on render prop pattern, more details here.

This pattern can also be used in different cases, not just data access.

Leave a comment