Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/heineiuo/use-promise-state
A React hook for Promise
https://github.com/heineiuo/use-promise-state
promise react react-hooks reacthooks use-promise-state use-state
Last synced: 1 day ago
JSON representation
A React hook for Promise
- Host: GitHub
- URL: https://github.com/heineiuo/use-promise-state
- Owner: heineiuo
- Created: 2018-11-14T05:47:50.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2018-11-14T06:07:52.000Z (about 6 years ago)
- Last Synced: 2024-11-02T00:08:52.287Z (18 days ago)
- Topics: promise, react, react-hooks, reacthooks, use-promise-state, use-state
- Language: JavaScript
- Homepage:
- Size: 1000 Bytes
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# usePromiseState()
Like `React.useState()` but use promise value
Inspired by [react-use-promise](https://github.com/bsonntag/react-use-promise)
## Install
```sh
yarn add use-promise-state
```## Usage
```jsx
import React from 'react'
import usePromiseState from 'use-promise-state'function Example (){
const [{state, error, result}, setPromise] = usePromiseState()return (
state: {state}
result: {result || ''}
setPromsie(new Promise(resolve => setTimeout(() => resolve('hello'), 10000)))}>start
setPromise(null)}>cancel
)
}
```## License
MIT