ReduxAsyncConnect for React Router
How do you usually request data and store it to redux state? You create actions that do async jobs to load data, create reducer to save this data to redux state, then connect data to your component or container.
Usually it's very similar routine tasks.
Also, usually we want data to be preloaded. Especially if you're building universal app, or you just want pages to be solid, don't jump when data was loaded.
This package consist of 2 parts: one part allows you to delay containers rendering until some async actions are happening. Another stores your data to redux state and connect your loaded data to your container.
Notice
This is a fork and refactor of redux-async-connect
Installation & Usage
Using npm:
$ npm install --save react-redux-async-connect
;; // 1. Connect your data, similar to react-redux @connect@Component { // 2. access data as props const lunch = thispropslunch return <div>lunchname</div> } // 3. Connect redux async reducerconst store = ; // 4. Render `Router` with ReduxAsyncConnect middleware
Server
;;;; app { return ` <!doctype html> <html> <body> <div id="app"></div> <!-- its a Redux initial data --> <script dangerouslySetInnerHTML={{__html: `window__data=$;`}} charSet="UTF-8"/> </body> </html> `}
applyRouterMiddleware
Usage with Thanks to @mmahalwy for a good usage example
Pass custom render
method to ReduxAsyncConnect
, it can look like this:
// on clientconst component = <Router render= <ReduxAsyncConnect ...props helpers= client filter= !itemdeferred render= /> history=history routes= />;
Basically what you do is instead of using render method like:
const render = <RouterContext ...props />;
you use
const render = ;