Git Product home page Git Product logo

koa-rrr's Introduction

Koa-RRR

An opinionated Koa middleware for React/React-router/Redux.

Installation

npm i --save koa-rrr

Usage

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>`
}))

API

koaRrr(options) -> Middleware Returns a koa middleware that will render a react app using react-router and redux

Options

routes [ReactRouter|function] Required

Either static routes, or a function taking the redux store and returning routes

createStore [function] Required

A function that creates the redux store

template [function] Required

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

wrap [function] Optional

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>
}

koa-rrr's People

Stargazers

Apostolos Tsakpinis avatar

Watchers

James Cloos avatar Max Polun avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.