# @mivia/react-promise-button

> react-romise-button

Latest version **1.0.4** (published 2019-08-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install @mivia/react-promise-button
pnpm add @mivia/react-promise-button
yarn add @mivia/react-promise-button
bun add @mivia/react-promise-button
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2019-08-11 |
| First published | 2019-08-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 27.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Michał Wiaderek |
| Maintainers | mivia |
| Keywords | button, promise, promise button, react button, state button, stateful |

## Links

- npm: https://www.npmjs.com/package/@mivia/react-promise-button
- Repository: https://github.com/mivia/react-promise-button
- Homepage: https://github.com/mivia/react-promise-button#readme
- Issues: https://github.com/mivia/react-promise-button/issues
- npm.io page: https://npm.io/package/@mivia/react-promise-button

## Dependencies (3)

- [classnames](https://npm.io/package/classnames.md) ^2.2.6
- [prop-types](https://npm.io/package/prop-types.md) ^15.6.0
- [make-cancellable-promise](https://npm.io/package/make-cancellable-promise.md) ^1.0.0

## Alternatives

- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads
- [fa](https://npm.io/package/fa.md) — 185 weekly downloads

## Recent versions

- 1.0.4 (latest) — 2019-08-11
- 1.0.3 — 2019-08-04
- 1.0.2 — 2019-08-03
- 1.0.1 — 2019-08-02

## README

[![Build Status](https://travis-ci.com/mivia/react-promise-button.svg?branch=master)](https://travis-ci.com/mivia/react-promise-button) ![dependencies](https://img.shields.io/david/mivia/react-promise-button.svg) ![dev dependencies](https://img.shields.io/david/dev/mivia/react-promise-button.svg)

# React-Promise-Button
A promise-button for you react app.
## Installation
Add react-promise-button to your project by executing `npm install @mivia/react-promise-button` or `yarn add @mivia/react-promise-button`.
## Demo
[Preview](https://mivia.github.io/react-promise-button/) available!
## Usage
Here's an example of basic usage:
```js
import React, { Component } from 'react';
import PromiseButton from '@mivia/promise-button';

const pendingConfig = {
  className: `PromiseButton--pending`,
  children: (
    <span>
      Pending!
    </span>
  ),
};

const successConfig = {
  className: `PromiseButton--success`,
  children: (
    <span>
      Success done!
    </span>
  ),
};

export default class Example extends Component {
  onClickSuccess = () => new Promise((resolve) => {
    setTimeout(() => {
      resolve('Success!');
    }, 2000);
  })

  render() {
    return (
      <PromiseButton
        onClick={this.onClickSuccess}
        pendingConfig={pendingConfig}
        successConfig={successConfig}
      >
        Gonna be success
      </PromiseButton>
    );
  }
}
```
## User guide
### Props
|Prop name|Description|Default value|Example values|
|----|----|----|----|
|className|Class name(s) that will be added to the button element.|n/a|`"class1 class2"`|
|onClick|A required callback function returning a promise.|n/a|`() => Promise.resolve()`|
|pendingConfig|Config including className and children that decorates the button when promise is pending.|n/a|`{className: "PromiseButton--pending", children: (<h2>Pending!</h2>)}`|
|successConfig|Config including className and children that decorates the button when promise has been successful.|n/a|`{className: "PromiseButton--success", children: (<h2>Success!</h2>)}`|
|errorConfig|Config including className and children that decorates the button when promise has failed.|n/a|`{className: "PromiseButton--error", children: (<h2>Error!</h2>)}`|
|refreshTimeout|Time that has to pass before switching back to initial config of the button after the promise is done, in miliseconds.|`2000`|`3000`|

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