React Redux Resolve
Experimental library to universally resolve your component's initial data. Per component you can specify a resolver
. On the client side, the resolver
is executed in componentDidMount()
and on the server-side once you call waitForResolves(renderProps, store)
. This makes server-side rendering easy to implement!
; @ { const sandwich = thisprops; return <Sandwich sandwich=sandwich /> ; }
Where fetchSandwich()
is something like the below (please note the example doesn't handle errors). This requires the redux-thunk middleware:
{ return { ; return ; };}
Now, say you're rendering your app on the server, you can easily access the @resolve()
. You can do this by accessing .resolves
on the components. We've created a helper method called waitForResolves(renderProps, store)
to do this:
; // Set up your server-side rendering like you normally would do. ;
API
resolve(resolver)
@ ;
resolver
receives an object with the following keys as argument:
dispatch
: the store's dispatch functiongetState
: the store's getState functionhistory
: the history object from your routerparams
: the params object from the routequery
: the query object from the route
Please note resolve()
returns a new component wrapped with the target component, similar to connect()
. To use resolve()
in ES5, try the following:
MyComponent = MyComponent;