
Security News
Socket Releases Free Certified Patches for Critical vm2 Sandbox Escape
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.
react-conditional-block
Advanced tools
A light weight conditional block component to help you clean up your react code
React Conditional Block is a light weight component that gives you a conditional block to help you clean up your react code. A common pattern in React is to have multiple conditions in your render method which control when certain blocks are rendered. This can turn into a mess quite quickly.
For example, with React Conditional Block, something which might originally have looked like this:
import React from 'react';
import {First, Second, Third, Other} from 'some-components';
const Component = ({first, second, third, ...rest}) => {
return (
<div>
{
first && (
<First {...rest} />
)
}
{
second && (
<Second {...rest}>
{
third && (
<Third {...rest} />
)
}
<Other>
<div>Inner</div>
</Other>
</Second>
)
}
</div>
);
};
Becomes something like this:
import React from 'react';
import {First, Second, Third, Other} from 'some-components';
import Conditional from 'react-conditional-block';
const Component = ({first, second, third, ...rest}) => {
return (
<div>
<Conditional predicate={first}>
<First {...rest} />
</Conditional>
<Conditional predicate={second}>
<Second {...rest}>
<Conditional predicate={third}>
<Third {...third} />
</Conditional>
<Other>
<div>Inner</div>
</Other>
</Second>
</Conditional>
</div>
);
};
The easiest way to use react-conditional-block is to install it from npm and build it into your app with Webpack
npm install --save react-conditional-block
Then use it in your app:
import React from 'react';
import Conditional from 'react-conditional-block';
const App = ({somethingTruthy, somethingFalsy}) => {
return (
<div>
<Conditional
predicate={somethingTruthy}>
I am rendered!
</Conditional>
<Conditional
predicate={somethingFalsy}>
I am NOT rendered!
</Conditional>
</div>
);
};
export default App;
Props you may want to specify include:
children - Any renderable content. Will be displayed when predicate is truthy.predicate - Boolean. This determines whether or not to render the children wrapped by Conditional.If you are interested you can follow me on twitter
MIT Licensed. Copyright (c) Matt Shirlaw 2019.
FAQs
A light weight conditional block component to help you clean up your react code
The npm package react-conditional-block receives a total of 0 weekly downloads. As such, react-conditional-block popularity was classified as not popular.
We found that react-conditional-block 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
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.

Research
Five malicious NuGet packages impersonate Chinese .NET libraries to deploy a stealer targeting browser credentials, crypto wallets, SSH keys, and local files.

Security News
pnpm 11 turns on a 1-day Minimum Release Age and blocks exotic subdeps by default, adding safeguards against fast-moving supply chain attacks.