paypal / react-engine

a composite render engine for universal (isomorphic) express apps to render both plain react views and react-router views
Apache License 2.0
1.45k stars 130 forks source link

Support redux #171

Closed 7aos closed 8 years ago

7aos commented 8 years ago

This is to bring in redux/react-redux support: https://github.com/paypal/react-engine/issues/168

Store initialization at client side Redux store create function initStore is passed to react-engine.client via boot options, which is invoked when wrap root component with react-redux Provider. The root component can be either react-router component or a vanilla react component.

Example

var reducer;
...
client.boot({
  ...
  redux: {
    initStore: function(state) {
      return Redux.createStore(reducer, state);
    }
  }
});

Store initialization at server side Similarly, a create function is needed to initialize the redux store. This function is provided through an optional config. Sample Kraken config

{
  ...
  "view engines": {
    "jsx": {
      "module": "react-engine/lib/server",
      "renderer": {
        "method": "create",
        "arguments": [
          {
            "routes": "require:./.build/routes/index.js",
            "redux": {
              "initStore": "path:./.build/store/init.js"
            }
          }
        ]
      }
    }
  }
 ...
}
SOSANA commented 8 years ago

@samsel @taosbeta any change we could provide a redux example in this repo?

7aos commented 8 years ago

Sure, that is a great idea! I will add an example shortly. Thanks.

IRT-fbachmann commented 7 years ago

Can the function initStore be called asynchronously? Especially interesting for server side rendering and prefetching initial state...