A ReactJS conditional rendering higher order component.
with npm
npm install bloom-conditionals
with yarn
yarn add bloom-conditionals
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>
}