react-promised-component
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=thispromiseGenerator promise_prop_params=thispromiseParams onError= { /* Do somethig with error */ } onSuccess= { /* 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 ref= thisscrInst = inst /> // Later in the code thisscrInst;
License
MIT © Amir Ali Jiwani