1.0.2 • Published 7 years ago
react-jsx-conditional v1.0.2
react-jsx-conditional
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-conditionalUsage
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>
}
/>| Props | Type | Required |
|---|---|---|
| expression | boolean | Yes |
| trueChild | Node/Array | Yes |
| trueChild | Node/Array | No |
Development
We welcome any pull requests, fork the repo and get started:
Install dependencies:
$ npm installRun the example app at http://localhost:3000:
$ npm startRun tests and watch for code changes using jest:
$ npm testLint src and test files:
$ npm run lintLicense
MIT