I need a component when a promise succeeds, fails or during loading This package would come handy in that case.
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
<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
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();
MIT © Amir Ali Jiwani