Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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()
- Host: GitHub
- URL: https://github.com/djgrant/redux-ready
- Owner: djgrant
- Created: 2017-02-03T02:48:58.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-06-07T12:14:57.000Z (over 7 years ago)
- Last Synced: 2024-04-26T04:45:36.130Z (7 months ago)
- Topics: redux, ssr
- Language: JavaScript
- Size: 26.4 KB
- Stars: 11
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
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 });
});```