
Security News
OWASP 2025 Top 10 Adds Software Supply Chain Failures, Ranked Top Community Concern
OWASP’s 2025 Top 10 introduces Software Supply Chain Failures as a new category, reflecting rising concern over dependency and build system risks.
babel-plugin-jsx-conditional-component
Advanced tools
Neater control exists component or component type for jsx
The plugin is a fork of babel-plugin-jsx-base-component made by Yurii Khmelvskii. Originally it was forked to add support for Babel 7 but unfortunately my PR wasn't approved.
This is Babel 7 plugin allowing to use <Base /> component in your jsx.
It has two properties:
exists - specifies whether the component content is showncomponent - shows which component <Base /> actually is. It is <div /> by defaultIn addition <Base /> component can take properties, that will be passed to component.
This component can help make your render method more readable and concise.
To show the purpose of <Base /> component let's consider its variants of use
and the result of its transformation:
1. List ul content is any.
<Base exists={props.comments.length !== 0} component="ul">
...
</Base>
After transformation:
{ props.comments.length !== 0 ? <ul> ... </ul> : null }
2. You can use conditions in component property, and also pass any react-components to it.
<Base component={props.targetBalnk ? 'a' : Link} href="/dashboard">
Dashboard
</Base>
After transformation:
const Component = props.targetBalnk ? 'a' : Link;
...
return (
<Component href="/dashboard">
Dashboard
</Component>
);
3. Complex Example.
<Base
component={props.status === 'important' || props.blockApp ? ImportantBar : AlertBar}
exists={props.isOpen || props.blockApp}
className={scss.alertBar} icon="car" text={props.text}
/>
After transformation:
const Component = props.status === 'important' || props.blockApp ? ImportantBar : AlertBar;
...
return (
{
props.isOpen || props.blockApp
? <Component className={scss.alertBar} icon="car" text={props.text} />
: null
}
);
Note: After transformation this plugin does not create any additional spans or other wrapping tags.
As a prerequisite you need to have Babel installed and configured in your project.
Install via npm:
npm install babel-plugin-jsx-conditional-component --save-dev
Then you only need to specify jsx-base-component as Babel plugin, which you would typically do in your .babelrc:
"plugins": [
...
"jsx-base-component"
]
Since <Base /> component is transformed using Babel, you don't need
to import (import) or plug it in (require). But in its turn
it will result in ESLint warning that Base variable is undefined.
To fix this, just add Base as global variable in your .eslintrc
"globals": {
...
"Base": true
}
FAQs
Neater control exists component or component type for jsx
The npm package babel-plugin-jsx-conditional-component receives a total of 17 weekly downloads. As such, babel-plugin-jsx-conditional-component popularity was classified as not popular.
We found that babel-plugin-jsx-conditional-component 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
OWASP’s 2025 Top 10 introduces Software Supply Chain Failures as a new category, reflecting rising concern over dependency and build system risks.

Research
/Security News
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.