1.0.2 • Published 7 years ago

render-if-react v1.0.2

Weekly downloads
5
License
ISC
Repository
github
Last release
7 years ago

react-render-if

HOC to render component with condition

Installation

npm install --save render-if-react

Limitation

Class component must be render as child.

Props

NameDescriptionDefault
conditionCondition to rendertrue
componentComponent to be render when condition is true
elseComponentComponent to be render when condition is false
strictMode to handle invalid component true: throw Error, false: log warningfalse

Example render as props

import RenderIf from 'render-if-react'

const Hello = () => <h1>Hello</h1>

class MyComponent extends Component {
    render() {
        return (
            <div>
                <RenderIf condition={1 + 1 === 2} component={<Hello />} />
            </div>
        );
    }
}

Example child component

import RenderIf from 'render-if-react'

class Hello extends Component {
    render() {
        return (
            <h3>Hello</h3>
        );
    }
}

class MyComponent extends Component {
    render() {
        return (
            <div>
                <RenderIf condition={1 + 1 === 2}>
                    <Hello />
                </RenderIf>
            </div>
        );
    }
}

Example else component

import RenderIf from 'render-if-react'

class Hello extends Component {
    render() {
        return (
            <h3>Hello</h3>
        );
    }
}

const ElseComponent = () => <div>Else Component</div>

class MyComponent extends Component {
    render() {
        return (
            <div>
                <RenderIf condition={0} elseComponent={ElseComponent}>
                    <Hello />
                </RenderIf>
            </div>
        );
    }
}
1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago