An opinionated Koa middleware for React/React-router/Redux.
npm i --save koa-rrr
let app = koa()
let routes = (
<Router history={history}>
<Route path='/page1' component={PageOne} />
</Router>
)
let koaRrr = require('koa-rrr')
let initStore = require('./initStore')
app.use(koaRrr({
routes,
createStore: initStore,
template: html => `<html><body>${html}</body></html>`
}))
koaRrr(options) -> Middleware Returns a koa middleware that will render a react app using react-router and redux
Either static routes, or a function taking the redux store and returning routes
A function that creates the redux store
A function taking the rendered react markup, and returning the complete html for the page
passed arguments:
- html: the rendered react html
- state: the redux state after the render is complete, can be used to rehydrate state quickly when the app loads
A function that will wrap your react app prior to rendering. This is used if you have Provider
type components that must be provided at the root of the app. The default version is equivalent to
let Provider = require('react-redux').Provider
function wrap(routingContext, store) {
return <Provider store={store}><routingContext /></Provider>
}