npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-inline-logic

v0.0.12

Published

This component encapsulates some opperations as if, while and for to be used as one Tag inside JSX to compose some logical expression inline.

Readme

React Inline Logic component

This component encapsulates some opperations as if, else, for and repeat to be used as one Tag inside JSX to compose some logical expression inline.

What problem this component solves?

When you have small logic inside your .jsx and you wish to make it more readeble. When you are implementing one functional .jsx component and wish to compose the logic inline. When you whant to repeat or show one list of elements and don't whant to create one new extra function do to it, you can use this component.

What is in the box?

You can work with the folow expressions as one jsx Tag:

<If/> <Else/> <For/> <IsTrue/> <IsFalse/> <Loop/> <Repeat/>

Installation

$ npm install react-inline-logic

Import

import {If, For, Else, IsTrue, IsFalse, Loop, Repeat} from 'react-inline-logic';

Implementation examples

If and Else

...
//using render method
render(){
    return (<div>
        <If condition={this.state.showDiv}>
            <div>
                This is my div to be showed
                <span>Cool!</span>
            </div>
        </If>
        <Else condition={this.state.showDiv}>
            <div>
                This must to be showed when this.state.showDiv is false
            </div>
        </Else>
    </div>);
}
...
//using in one functional component
const MyConditionalDiv = ({visible=true})=>(<div>
        <If condition={visible}>
            <div>
                This is my div to be showed
                <span>Cool!</span>
            </div>
        </If>
        <Else condition={visible}>
            <div>
                This must to be showed when this.state.showDiv is false
            </div>
        </Else>
    </div>);
}
//if you hate the if in your logic you can use these alias 
const MyConditionalDiv = ({visible=true})=>(<div>
        <IsTrue condition={visible}>
            <div>
                This is my div to be showed
                <span>Cool!</span>
            </div>
        </IsTrue>
        <IsFalse condition={visible}>
            <div>
                This must to be showed when this.state.showDiv is false
            </div>
        </IsFalse>
    </div>);
}
//or this
const MyConditionalDiv = ({visible=true})=>(<div>
        <If condition={visible}>
            <div>
                This is my div to be showed
                <span>Cool!</span>
            </div>
        </If>
        <IfNot condition={visible}>
            <div>
                This must to be showed when this.state.showDiv is false
            </div>
        </IfNot>
    </div>);
}

For, Repeat and Loop

...
//using render method
//this pseudo code will render one select with tree different options.
render(){
    let list = [{id:'au', value:'Australia', text:'AUS'},{id:'br', value:'Brazil', text:'BRZ'},{id:'nz', value:'New Zeland', text:'NZL'}];

    return (<select>
        <For list={list} onLoop={(item, index)=>(
            <option key={item.id} value={item.id}>{item.value}</option>
        )}/>
        </select>);
}
...
//functional component
//this pseudo code will render one select with tree different options.
const MySelectDemo = ({list=[]})=>(
    <select>
        <For list={list} onLoop={(item, index)=>(
            <option key={item.id} value={item.id}>{item.value}</option>
        )}/>
    </select>
);
...
//breaking the loop using onLoopBreakIf method.
render(){
    let list = [{id:'au', value:'Australia', text:'AUS'},{id:'br', value:'Brazil', text:'BRZ'},{id:'nz', value:'New Zeland', text:'NZL'}];

    return (<select>
        <For list={list} onLoop={(item, index)=>(
            <option key={item.id} value={item.id}>{item.value}</option>
        )} onLoopBreakIf={(item, index)=>item.id==='br'}/>
        </select>);
}
...
//continuing the loop using onLoopContinueIf method.
//the pseudo code will render just the first and last option.
render(){
    let list = [{id:'au', value:'Australia', text:'AUS'},{id:'br', value:'Brazil', text:'BRZ'},{id:'nz', value:'New Zeland', text:'NZL'}];

    return (<select>
        <For list={list} onLoop={(item, index)=>(
            <option key={item.id} value={item.id}>{item.value}</option>
        )} onLoopContinueIf={(item, index)=>item.id==='br'}/>
        </select>);
}
...
//Using onLoopComplete to count the results for instance
render(){
    let list = [{id:'au', value:'Australia', text:'AUS'},{id:'br', value:'Brazil', text:'BRZ'},{id:'nz', value:'New Zeland', text:'NZL'}];

    return (<select>
        <For list={list} onLoop={(item, index)=>(
            <option key={item.id} value={item.id}>{item.value}</option>
        )} onLoopComplete={(list, index)=>this.state.optionsCount = index}/>
        </select>);
}

Also You can use the 'For' alias as <Repeat/> or <Loop/>

repo

https://github.com/elninhojs/react-inline-logic

License

MIT