bloom-conditionals
v1.0.2
Published
A ReactJS Conditional Component without external dependencies.
Downloads
4
Readme
bloom-conditionals
A ReactJS conditional rendering higher order component.
Install
with npm
npm install bloom-conditionals
with yarn
yarn add bloom-conditionals
Usage
Simple static values test:
import { Condition, When, Else } from "bloom-conditionals";
const myComponent = (props) => {
return <Condition test={props.someValue}>
<When true>I am True</When>
<When false>I am False</When>
<Else>I render when no When or NotWhen renders</Else>
</Condition>
}
Test specific values:
import { Condition, When, Else } from "bloom-conditionals";
const myComponent = (props) => {
return <Condition test={props.someValue}>
<When value={true}>I am True</When>
<When value={false}>I am False</When>
<Else>I render when no When or NotWhen renders</Else>
</Condition>
}
Test using functions
import { Condition, When, Else } from "bloom-conditionals";
const myComponent = (props) => {
return <Condition test={props.someValue}>
<When value={v => v === true}>I am True</When>
<When value={v => v === false}>I am False</When>
<Else>I render when no When or NotWhen renders</Else>
</Condition>
}