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

jsxcond

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsxcond

A simple lisp style if-else-then / cond utilify for react/jsx

latest
Source
npmnpm
Version
0.1.0
Version published
Weekly downloads
3
-50%
Maintainers
1
Weekly downloads
 
Created
Source

JSXCOND

Build Status js-standard-style npm

Installation

npm install jsxcond --save

Usage

if-else-then

_if (TEST_FORM, THEN_FORM, [ELSE_FORM])

  • Common Usage
import React from 'react';
import { _if } from 'jsxcond'

class SomeComponent extends React.Component {
  render() {
    const condition = true;
    <div>
      {_if ( condition, () => (
        <span>
          condition is true
        </span>
      ), () => (
        <span>
          condition is false
        </span>
      ))}
    </div>
  }
}
  • Only if, no else
import React from 'react';
import { _if } from 'jsxcond'

class SomeComponent extends React.Component {
  render() {
    const condition = true;
    <div>
      {_if ( condition, () => (
        <span>
          condition is true
        </span>
      ))}
    </div>
  }
}
  • TEST_FORM can be a function
import React from 'react';
import { _if } from 'jsxcond'

class SomeComponent extends React.Component {
  render() {
    const condition = true;
    <div>
      {_if ( () => {
        return true
      }, () => (
        <span>
          condition is true
        </span>
      ), () => (
        <span>
          condition is false
        </span>
      ))}
    </div>
  }
}
  • Recommend using () => () to have lazy eval(). However THEN_FORM and ELSE_FORM are still supported.
import React from 'react';
import { _if } from 'jsxcond'

class SomeComponent extends React.Component {
  render() {
    const condition = true;
    <div>
      {_if ( condition, 'condition is true', (
        <span>
          condition is false
        </span>
      ))}
    </div>
  }
}

cond

if-else-then

_cond (STATEMENT1, STATEMENT2...)

STATEMENT can be array, function, common value:

  • When it is a value, it will be returned immediately.

  • When it is a function, it will be evaluated and returned immediately.

  • When it is a array, the first value will be used as TEST_FORM, and the second will be used as THEN_FORM.

  • Common Usage

import React from 'react';
import { _cond } from 'jsxcond'

class SomeComponent extends React.Component {
  render() {
    const condition = 3
    <div>
      {_cond (
        [condition === 1, () => (
          <span>
            condition is 1
          </span>
        )],
        [condition === 2 , () => (
          <span>
            condition is 2
          </span>
        )], () => (
          <span>
            Otherwise
          </span>
        )}
    </div>
  }
}
  • TEST_FORM can be a function
import React from 'react';
import { _cond } from 'jsxcond'

class SomeComponent extends React.Component {
  const condition = 3;
  render() {
    <div>
      {_cond (
        [
          () => {
            return condition === 1
          }, () => (
            <span> condition is 1 </span>
          )
        ],
        [
          () => {
            return condition === 2
          }, () => (
            <span> condition is 2 </span>
          )
        ]
      )}
    </div>
  }
}

License

MIT

Keywords

react

FAQs

Package last updated on 25 Mar 2016

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