New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

jsx-control

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsx-control

Neater control statements (if/for) for JSX

1.0.7
latest
Source
npm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

JSX Control

This has been deprecated in favour of https://github.com/valtech-au/jsx-control-statements now that it supports nesting

A JSTransform that adds syntactical sugar that turns <If> and <For> elements into control statements.

Usage

If

<If condition={this.props.banner}>
  <Banner />
 </If>

turns into...

{function() {
  if (this.props.banner) {
    return (<Banner />)
  }
}.call(this)}

The <If> body must return a single JSX root element. You can even nest!

<If condition={this.props.banner}>
  <div className="banner">
    <Banner />
    <If condition={this.props.user && this.props.user.avatar}>
      <Picture avatar={this.props.user.avatar} />
    </If>
  </div>
</If>

For

<For each="fruit" of={this.props.fruits}>
  <li key={fruit}>{fruit}</li>
</For>

this becomes

this.props.fruits.map(function(fruit) { return (
  <li key={fruit}>{fruit}</li>
)}, this)

Installation

  npm install jsx-control

Webpack

A visitorList is available through jsx-control/visitors, which can be used in conjunction with JSTransform Loader.

Browserify

Include 'jsx-control/browserify' in your transform array

node-jsx

The transform can be added during the install function of node-jsx

var jsxControl = require('jsx-control');
require('node-jsx').install({
  extension: '.jsx',
  additionalTransform: function(src) {
    return jsxControl(src);
  }
});

Thanks!

to valtech-au/jsx-control-statements for the inspiration! This module is slightly different in that it eschews <Else> in favour of nested <Ifs>, as well as constructing the statements slightly differently.

Keywords

react

FAQs

Package last updated on 03 Jun 2015

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