Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
react-inline-logic
Advanced tools
This component encapsulates some opperations as if, while and for to be used as one Tag inside JSX to compose some logical expression inline.
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.
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.
You can work with the folow expressions as one jsx Tag:
<If/> <Else/> <For/> <IsTrue/> <IsFalse/> <Loop/> <Repeat/>
$ npm install react-inline-logic
import {If, For, Else, IsTrue, IsFalse, Loop, Repeat} from 'react-inline-logic';
...
//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>);
}
...
//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/>
https://github.com/elninhojs/react-inline-logic
MIT
FAQs
This component encapsulates some opperations as if, while and for to be used as one Tag inside JSX to compose some logical expression inline.
The npm package react-inline-logic receives a total of 13 weekly downloads. As such, react-inline-logic popularity was classified as not popular.
We found that react-inline-logic demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.