Skip to content

Latest commit

 

History

History
71 lines (54 loc) · 1.76 KB

README.md

File metadata and controls

71 lines (54 loc) · 1.76 KB

bloom-conditionals

Travis npm package Coveralls

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>
}