Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/t1amat9409/react-query

From a medium article by Tim Kolberger, https://medium.com/@TimKolb/creating-a-reusable-react-query-component-for-your-rest-api-1aa91ef2551b
https://github.com/t1amat9409/react-query

api fetch query react react-native

Last synced: about 2 months ago
JSON representation

From a medium article by Tim Kolberger, https://medium.com/@TimKolb/creating-a-reusable-react-query-component-for-your-rest-api-1aa91ef2551b

Awesome Lists containing this project

README

        

# @itxbornfire/react-query

From Tim's article, and the codesandbox he peovided, this is how a basic component should look like.
Of course you can style it as you wish as shown here https://codesandbox.io/s/92n5zmoq2y?from-embed .

```JavaScript
import React, { Fragment } from "react";
import { Query } from "@itxbornfire/react-query";

import {
LoadingComponent,
ErrorComponent
} from ".../path/to/your/components";

export const BasicQuery = () => (

BasicQuery



{({ state: { data, loading, error }, actions }) => {
if (loading) {
return ;
}

if (error) {
return ;
}

if (data) {
return (


Reload

{
//render your data
}

);
}

return null;
}}


);

```
Here's an interactive sandbox, the original sandbox by Tim himself.

[![Edit 92n5zmoq2y](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/92n5zmoq2y)