react-ternary

0.1.3 • Public • Published

react-ternary

Use ternary conditional operator in a declarative way.

Installation

npm install react-ternary --save

Usage

Instead of:

import React, { Component } from 'react'

class App extends Component {
  render() {
    return(
      <div>
        {
          this.props.language === 'JS' ? 
            <div>Language is JS</div> : 
            <div>Language is not JS</div>
        }
      </div>
    )
  }
}

you can use ternary in a declarative way:

import React, { Component } from 'react'
import Ternary from 'react-ternary'

class App extends Component {
  render() {
    return(
      <Ternary condition={this.props.language === 'JS'}>
        <div>Language is JS</div>     {/* first element will render if condition is true */}
        <div>Language is not JS</div> {/* second element will render if condition is false */ }
      </Ternary>
    )
  }
}

Package Sidebar

Install

npm i react-ternary

Weekly Downloads

0

Version

0.1.3

License

MIT

Unpacked Size

7.28 kB

Total Files

8

Last publish

Collaborators

  • da_vinci