React bindings for NornJ template engine.
npm install nornj-react
You can use bindTemplate
to register React components to NornJ
template engine.
- Class components
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import nj from 'nornj';
import { bindTemplate } from 'nornj-react';
@bindTemplate
class TestComponent extends Component {
render() {
return <i>{this.props.children}</i>;
}
}
ReactDOM.render(nj`<TestComponent>test</TestComponent>`(), document.body);
In addition, bindTemplate
also support a name
parameter:
...
import { bindTemplate } from 'nornj-react';
@bindTemplate('test-Component')
class TestComponent extends Component {
render() {
return <i>{this.props.children}</i>;
}
}
ReactDOM.render(nj`<test-Component>test</test-Component>`(), document.body);
- Function components
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import nj from 'nornj';
import { bindTemplate } from 'nornj-react';
const TestComponent = bindTemplate('test-Component')(props => (
<i>{props.children}</i>
));
ReactDOM.render(nj`<test-Component>test</test-Component>`(), document.body);
MIT