# use-promise-state

> Like `React.useState()` but use promise value

Latest version **0.0.1** (published 2018-11-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install use-promise-state
pnpm add use-promise-state
yarn add use-promise-state
bun add use-promise-state
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2018-11-14 |
| First published | 2018-11-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | heineiuo |
| Maintainers | heineiuo |

## Links

- npm: https://www.npmjs.com/package/use-promise-state
- Repository: https://github.com/heineiuo/use-promise-state
- Homepage: https://github.com/heineiuo/use-promise-state#readme
- Issues: https://github.com/heineiuo/use-promise-state/issues
- npm.io page: https://npm.io/package/use-promise-state

## Recent versions

- 0.0.1 (latest) — 2018-11-14

## 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 (
    <div>
      <div>state: {state}</div>
      <div>result: {result || ''}</div>
      <button onClick={() => setPromsie(new Promise(resolve => setTimeout(() => resolve('hello'), 10000)))>start</button> 
      <button onClick={() => setPromise(null)>cancel</button> 
    </div>
  )
}
```

## License
MIT

---
_Source: https://npm.io/package/use-promise-state · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
