react-promised-component

0.0.12 • Public • Published

react-promised-component NPM version Build Status Dependency Status Coverage percentage

I need a component when a promise succeeds, fails or during loading This package would come handy in that case.

Surpise: It has a yeoman generator as well!

Installation

npm (we assume you have pre-installed node.js). We assume, you have a running React project as well.

npm install react-promised-component --save

Leave the rest for Yeoman to take care of

yo react-promised-component

If you want to have a look at generator generator-react-promised-component

Usage

  <PromisedComponent
      promise_prop={this.promiseGenerator.bind(this)}
      promise_prop_params={this.promiseParams.bind(this)}
      onError={(error) => { /* Do somethig with error */ }}
      onSuccess={(result) => { /* Do somethig with result */ }}
    />
 
  // promise_prop (required): the method that generates a new promise
  // promise_prop_params (optional): the method that can generate parameters and magically supply it to promise creator
  // onError (optional): callback to notify error case with error as parameter
  // onSuccess (optional): callback to notify success case with result as parameter

Surprise

You can leverage a retry on promise if you want to without any fuss.

  <PromisedReactComponent
    promise_name={() => Promise.resolve(true)}
    ref={inst => (this.scrInst = inst)}
  />
 
  // Later in the code
  this.scrInst.retryPromise();

License

MIT © Amir Ali Jiwani

Dependents (0)

Package Sidebar

Install

npm i react-promised-component

Weekly Downloads

3

Version

0.0.12

License

MIT

Last publish

Collaborators

  • aajiwani