Released and used based on react backend rendering template engine noox, reactnoox

Source: Internet
Author: User

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:

  1. You need to learn the syntax defined by various template engines, such as {if }}, {loop }}
  2. 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:

  1. Header
  2. Body
  3. 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.