Simply render React components in Node.js
npm install react-node-render --save
const render = require('react-node-render')
const html = render('myComponent.jsx')
console.log(html)
const html = render('myComponent.jsx', {initialCount:42})
const html = render('myComponent.jsx', {initialCount:42},true)
Install:
npm install react-node-render -g
Use:
rnr myComponent.jsx
myComponent.html is now created
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
<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>
- 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.