Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/soorajshankar/re-promise-component
- Owner: soorajshankar
- Created: 2019-10-31T07:11:49.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2022-12-11T11:33:20.000Z (about 2 years ago)
- Last Synced: 2024-11-28T10:40:33.340Z (27 days ago)
- Language: JavaScript
- Size: 3.15 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 52
-
Metadata Files:
- Readme: README.md
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)