
Security News
PodRocket Podcast: Inside the Recent npm Supply Chain Attacks
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
@yookue/react-condition
Advanced tools
🏅 Render components conditionally for React 👍
1️⃣ Supports 'If' conditions. 2️⃣ Supports 'If'-'Then' conditions. 3️⃣ Supports 'If'-'Else' conditions. 4️⃣ Supports 'If'-'Then'-Else' conditions. 🔁 Supports 'For' conditions. 🔁 Supports 'Do' conditions. 🔁 Supports 'While' conditions.
You can install react-condition package in your existing react project as follows:
$ npm install @yookue/react-condition --save
Then, you may import components of react-condition as follows:
import {If, For, Switch, Do, While} from '@yookue/react-condition';
Enjoy your journey in coding your projects with react-condition. ✌️
Both of the
If.Then
andIf.Else
have arender
property (() => React.ReactNode), thus you can customize the rendering contents instead of the ReactChildren
.
If
statementimport {If} from '@yookue/react-condition';
export default () => {
const param = true;
return (
<If condition={param}>
<span>Hello World</span>
</If>
);
}
If
-Then
statementimport {If} from '@yookue/react-condition';
export default () => {
const param = 1;
return (
<If condition={param}>
<If.Then>
<span>Hello World</span>
</If.Then>
</If>
);
}
If
-Else
statementimport {If} from '@yookue/react-condition';
export default () => {
const param = false;
return (
<If condition={param}>
<span>Hello World</span>
<If.Else>
<span>Hello Yookue</span>
</If.Else>
</If>
);
}
If
-Then
-Else
statementimport {If} from '@yookue/react-condition';
export default () => {
const param = false;
return (
<If condition={param}>
<If.Then>
<span>Hello World</span>
</If.Then>
<If.Else>
<span>Hello Yookue</span>
</If.Else>
</If>
);
}
import {For} from '@yookue/react-condition';
export default () => {
return (
<For
of={['foo', 'bar']}
render={(item, index) => {
return (
<span key={index}>Hello, {item}</span>
);
}}
/>
);
}
Both of the
Switch.Case
andSwitch.Default
have arender
property (() => React.ReactNode), thus you can customize the rendering contents instead of the ReactChildren
.
import {Switch} from '@yookue/react-condition';
export default () => {
const username = 'admin';
return (
<Switch>
<Switch.Case condition={username.includes('admin')}>
<span>admin</span>
</Switch.Case>
<Switch.Case condition={username.includes('guest')}>
<span>guest</span>
</Switch.Case>
<Switch.Default>
<span>root</span>
</Switch.Default>
</Switch>
);
}
import {Do} from '@yookue/react-condition';
export default () => {
let param = 0;
return (
<Do
condition={() => {
return param < 2;
}}
render={(index) => {
param++;
return (
<span key={index}>Hello, {index}</span>
);
}}
/>
);
}
import {While} from '@yookue/react-condition';
export default () => {
let param = 0;
return (
<While
condition={() => {
return param++ < 2;
}}
render={(index) => {
return (
<span key={index}>Hello, {index}</span>
);
}}
/>
);
}
This project is under the MIT License (MIT)
FAQs
Render components conditionally for react
The npm package @yookue/react-condition receives a total of 15 weekly downloads. As such, @yookue/react-condition popularity was classified as not popular.
We found that @yookue/react-condition demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.