Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

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

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