1.0.2 • Published 6 years ago

react-jsx-conditional v1.0.2

Weekly downloads
7
License
MIT
Repository
github
Last release
6 years ago

react-jsx-conditional

npm

A lightweight conditional component which takes both a node and an array as children and renders based on a boolean expression.

This is a very simple conditional component for React 16 only which can take both react nodes to display or an array of nodes (meaning you can use an iterator in either the trueChild or falseChild) based on the conditional expression. It requires an expression and a trueChild but it does not require the falseChild as it will return null if none is passed through.

Installation

$ npm install react-jsx-conditional

Usage

All the possible usuages are listed in our examples page but below is probably the most standard usecase:

<Conditional
  expression={true}
  trueChild={
    <p>This is true</p>
  }
  falseChild={
    <p>This is false</p>
  }
/>
PropsTypeRequired
expressionbooleanYes
trueChildNode/ArrayYes
trueChildNode/ArrayNo

Development

We welcome any pull requests, fork the repo and get started:

Install dependencies:

$ npm install

Run the example app at http://localhost:3000:

$ npm start

Run tests and watch for code changes using jest:

$ npm test

Lint src and test files:

$ npm run lint

License

MIT

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.2.0

6 years ago

0.1.0

7 years ago