
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
@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
🔁 Supports 'MapIterator' conditions
🔁 Supports 'SetIterator' conditions
🔁 Supports 'ObjectIterator' conditions
You can install this package in your React project as follows:
$ npm install @yookue/react-condition --save
Then, you may import components as follows:
import {If, For, Switch, Do, While, MapIterator, SetIterator, ObjectIterator} from '@yookue/react-condition';
Enjoy your coding journey 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 React from 'react';
import {If} from '@yookue/react-condition';
export default () => {
const param = true;
return (
<If condition={param}>
<span>Hello World</span>
</If>
);
}
If
-Then
statementimport React from 'react';
import {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 React from 'react';
import {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 React from 'react';
import {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 React from 'react';
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 React from 'react';
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 React from 'react';
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 React from 'react';
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>
);
}}
/>
);
}
import React from 'react';
import {MapIterator} from '@yookue/react-condition';
export default () => {
const map = new Map([
['foo', 'bar'],
['hello', 'world'],
]);
return (
<MapIterator
of={map}
render={(value, key, index) => {
return (
<span key={index}>Hooray, {key}-{value}</span>
);
}}
/>
);
}
import React from 'react';
import {SetIterator} from '@yookue/react-condition';
export default () => {
const set = new Set<string>([
'foo-bar',
'hello-world',
]);
return (
<SetIterator
of={set}
render={(item, index) => {
return (
<span key={index}>Hooray, {item}</span>
);
}}
/>
);
}
import React from 'react';
import {ObjectIterator} from '@yookue/react-condition';
export default () => {
const param = {
'foo': 'bar',
'hello': 'world',
};
return (
<ObjectIterator
of={param}
render={(value, key, index) => {
return (
<span key={index}>Hooray, {key}-{value}</span>
);
}}
/>
);
}
This project is under the MIT License.
FAQs
Render components conditionally for react
The npm package @yookue/react-condition receives a total of 30 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
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.