Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/djgrant/redux-ready

store.ready().then()
https://github.com/djgrant/redux-ready

redux ssr

Last synced: 11 days ago
JSON representation

store.ready().then()

Awesome Lists containing this project

README

        

# redux-ready

Enhances your redux store with a `store.ready()` method, which resolves once all promises dispatched into the store are fulfilled.

Very handy for server rendering redux applications that initialise with async actions.

### Install

```sh
npm install redux-ready --save
```

### Setup

```js
var withReady = require("redux-ready");

var storeEnhancer = compose(
withReady, // make sure this comes first
applyMiddleware(thunk)
);

var store = createStore(reducers, storeEnhancer);
```

### Usage

```js
var app = ;

// Render the app initially to dispatch any actions in components' lifecycle
var html = renderToString(app);

// Wait for async actions to resolve
store
.ready()
.then(state => {
// Re-render app with the async data now in the store
html = renderToString(app);

// Serve the app html and state
res.status(200).render("reactView", { html, state });
})
.catch(error => {
// Serve an error page, or aleternatively, the app with an unresolved state
res.state(500).render("errorView", { error });
});

```