Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/soorajshankar/re-promise-component

React Promise resolver component, inspired from react apollo client. This will help to have result,loading,error states without initializing additional states or hooks
https://github.com/soorajshankar/re-promise-component

Last synced: 3 days ago
JSON representation

React Promise resolver component, inspired from react apollo client. This will help to have result,loading,error states without initializing additional states or hooks

Awesome Lists containing this project

README

        

# re-promise-component

> React Promise resolver component, inspired from react apollo client. This will help to have result,loading,error states without initializing additional states or hooks

[![NPM](https://img.shields.io/npm/v/re-promise-component.svg)](https://www.npmjs.com/package/re-promise-component) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

## Install

```bash
npm install --save re-promise-component
```

## Usage

```jsx
import React, { Component } from "react";
import RePromise from "re-promise-component";
import axios from "axios";

function delay(t, v) {
return new Promise(function(resolve) {
setTimeout(resolve.bind(null, v), t);
});
}
export default class App extends Component {
render() {
return (


{/* Resolving promises */}

{(result, error, loading) => {
if (loading) return "Loading..";
else if (error) return "Oops something went wrong!!";
else return
{JSON.stringify(result || "No data found")}
;
}}

{/* For making api calls */}

{(result, error, loading) => {
if (loading) return "Loading..";
else if (error) return "Oops something went wrong!!";
else return

{JSON.stringify(result || "No data found")}
;
}}


);
}
}
```

## License

MIT © [soorajshankar](https://github.com/soorajshankar)