0.0.8 • Published 7 years ago

unikoa-react-render v0.0.8

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

unikoa-react-render

NOTE: This is a WIP and not production ready yet

Unikoa middleware for rendering React apps universally

Example

Create head and body components, and specify script tags, and Unikoa React Render will render those components on the server, then re-render the body on the client.

const unikoa = require('unikoa')
const React = require('react')
const unikoaReactRender = require('unikoa-react-render')

const $ = React.DOM
const router = module.exports = unikoa()

const Head = React.createClass({
  render: function () {
    return $.head({},
      $.title('Hello World'))
  }
})

const Body = React.createClass({
  getInitialState: function () {
    return {secondsElapsed: 0}
  },
  tick: function () {
    this.setState({ secondsElapsed: this.state.secondsElapsed + 1 })
  },
  componentDidMount: function () {
    this.interval = setInterval(this.tick, 1000)
  },
  render: function () {
    return $.div({}, `Seconds Elapsed: ${this.state.secondsElapsed}`)
  }
})

// Load middleware with defaults configured
router.use(unikoaReactRender({
  head: Head,
  body: Body,
  scripts: ['/bundle.js'],
  subscribe: store.subscribe // Redux
}))

// Use ctx.render overidding defaults
router.get('/article/:id', (ctx, next) => {
  ctx.render({ body: Body })
})

Contributing

Please fork the project and submit a pull request with tests. Install node modules npm install and run tests with npm test.

License

MIT

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago