Released and used based on react backend rendering template engine noox, reactnoox
The concept of React componentization has attracted more and more developers' attention. componentization helps developers decouple pages into one component, and the code is more modular and easier to expand. Currently, the common backend template engines such as ejs, swig, jade, and art are:
- You need to learn the syntax defined by various template engines, such as {if }}, {loop }}
- Lack of strong componentization support, complex implementation, and ease of use
In view of the above pain points, the author created a tool such as noox Based on React, focusing on backend template parsing, making template parsing easier and easier to use.
Usage
Install
npm install noox
Simple demo
Template code
First, create a component directory and add a template file.
mkdir components && cd componentsvi Head.jsx
The content of Head. jsx is as follows:
Node. js Code
const noox = require('noox');const nx = new noox(path.resolve(__dirname, './components'), {title: 'noox'});let output = nx.render('Head', {description: 'hello, noox.'})
Output
Principle
Based on the Jsx of React, Noox simplifies component reference and creation. Assume that a directory structure is as follows:
components/ Header.jsx Body.jsx Layout.jsx
Run the following nodejs code:
nx = new noox(path.resolve(__dirname, './components'))
Three components will be created:
- Header
- Body
- Layout
Then use nx. render to render
nx.render('Body', props)
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.