react-node-render

0.0.7 • Public • Published

Travis NPM version Coverage Status

react-node-render

Simply render React components in Node.js

Node_module

npm install react-node-render --save

const render = require('react-node-render')
const html = render('myComponent.jsx')
console.log(html)

With options

const html = render('myComponent.jsx', {initialCount:42})

Render to static

const html = render('myComponent.jsx', {initialCount:42},true)

Cli

Install:

npm install react-node-render -g

Use:

rnr myComponent.jsx

myComponent.html is now created

Input

import React from 'react'
 
import React from 'react'
class component extends React.Component {
    constructor(props) {
        super(props)
        this.state = {count: props.initialCount}
    }
 
    handleClick(){
        this.setState({count: this.state.count + 1})
    }
    render() {
        return (
            <div onClick={this.handleClick.bind(this)}>
                hello {this.state.count}
            </div>
        )
    }
}
component.defaultProps = { initialCount: 1337 }
export default component
 

Output

<div data-reactid=".2c8ppxl2l1c" data-react-checksum="-143512554"><span data-reactid=".2c8ppxl2l1c.0">hello </span><span data-reactid=".2c8ppxl2l1c.1">1337</span></div>

or with static mode:

<div>hello 1337</div>

notes

  • todo fix .babelrc dependency
  • render to jade
  • render to hbs
  • rendering with react-router
  • more awesome tests
  • deeper error handeling
  • more cli features

Created mainly to shoot out html for koa/express.js servers used together with a templating language.

Package Sidebar

Install

npm i react-node-render

Weekly Downloads

4

Version

0.0.7

License

MIT

Last publish

Collaborators

  • morgondag