Skip to content

An Koa view engine which renders React components on server

Notifications You must be signed in to change notification settings

yandongxu/react-view

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

koa-react-view

NPM version build status Test coverage David deps node version

An Koa view engine which renders React components on server.

Installation

$ npm install koa-react-view

Usage

var react = require('koa-react-view');
var path = require('path');
var koa = require('koa');

var app = koa();

var viewpath = path.join(__dirname, 'views');
var assetspath = path.join(__dirname, 'public');

react(app, {
  views: viewpath,
  babel: {
    only: [
      viewpath,
      assetspath
    ]
  }
});

app.use(function* () {
  this.render(home, {foo: 'bar'});
});

Options

option values default
doctype any string that can be used as a doctype, this will be prepended to your document "<!DOCTYPE html>"
beautify true: beautify markup before outputting (note, this can affect rendering due to additional whitespace) false
views the root directory of view files path.join(__dirname, 'views')
extname the default view file's extname jsx
writeResp true: writes the body response automatically true
babel the options for babel/register {only: options.views}
cache true: cache all the view files process.env.NODE_ENV === 'production'

ctx.state

koa-react-view support ctx.state in koa.

License

MIT

About

An Koa view engine which renders React components on server

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 99.9%
  • Other 0.1%