New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

rct-express

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rct-express

This is a dead-simple way to display jsx code with express and pass it data.

latest
Source
npmnpm
Version
1.1.0
Version published
Maintainers
1
Created
Source

rct-express

This is a dead-simple way to display jsx code with express and pass it data.

Usage

Install

npm install rct-express --save

Include it

var parseRCT = require('rct-express').parseRCT

Add it to your app

res.send(parseRCT('pathto.jsx', obj));

Add it to your jsx

You can access the data you passed in to parseRCT via the variable name server_data.

If you havent already, make sure you add ReactDOM.render to your app:

ReactDOM.render(
  React.createElement(ShoppingList), //replace ShoppingList with your react class or your jsx element
  document.getElementById('app')
);

NOTE: there is no need to require react or react-dom, we deal with that part for you.

Example

server.js

var express = require('express');
var app = express();
var parseRCT = require('rct-express').parseRCT

app.use('/views', express.static('views'))

app.get('/', function(req, res){
 	res.send(parseRCT('/views/element.jsx', {name: 'john'}));
});

app.listen(3000, () => {
  console.log('listening on port 3000');
})

views/element.jsx

class ShoppingList extends React.Component {
  render() {
    return (
      <div className="shopping-list">
        <h1>Shopping List for {server_data.name}</h1>
        <ul>
          <li>Instagram</li>
          <li>WhatsApp</li>
          <li>Oculus</li>
        </ul>
      </div>
    );
  }
}


ReactDOM.render(
  React.createElement(ShoppingList),
  document.getElementById('app')
);

FAQs

Package last updated on 16 Sep 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts