react-redux-suspend
😬 React.Suspense
+ Redux
plugin
Installation
yarn add react-redux-suspend
Setup
Configure your store with just little bit of middleware boilerplate.
;; const suspendMiddleware = ; const store = ; // must be called after store is created abovesuspendMiddleware;
Usage
Decorate your component with the connect
as per usual, and then follow up with suspend
.
;;; let <p> Clicked: value times <button onClick=onIncrement>+</button> </p>; CounterpropTypes = value: PropTypesnumberisRequired onIncrement: PropTypesfuncisRequired; const mapStateToProps = value: state;const mapDispatchToProps = ; Counter = Counter; /* now for the extra part */ const mapStateToInvalidation = state === null;const mapStateToResolution = type: "INIT_ASYNC" ;const watchAction = actiontype === "INIT"; Counter = Counter;
Now while mapStateToInvalidation
evaluates to truthy, the nearest Suspense
component will be triggered.
Of course you'll need to wrap your newly suspendable component in a Suspense
component somewhere in your app.
const App = <Provider store=store> <Suspense fallback=<div>loading...</div>> <Counter/> </Suspense> </Provider>
License
MIT