Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
bem-react-helper
Advanced tools
A helper making it easier to name React components according to BEM convention.
Before:
export default class Block extends Component {
render() {
return (
<div className={`block ${this.props.visible ? 'block_visible' : ''} ${this.props.type ? `block_type_${this.props.type}` : ''} ${this.props.size ? `block_size_${this.props.size}` : 'block_size_m'} ${this.props.mix}`} />
);
}
}
Or:
export default class Block extends Component {
render() {
const classes = ['block'];
if (this.props.visible) classes.push('block_visible');
if (this.props.type) classes.push(`block_type_${this.props.type}`);
if (this.props.size) {
classes.push(`block_size_${this.props.size}`);
} else {
classes.push('block_size_m');
}
if (this.props.mix) classes.push(this.props.mix);
return (
<div className={classes.join(' ')} />
);
}
}
With usage like this:
<Block visible={true} type="primary" size="xxl" mix="block2__elem"/>
After:
import b from 'bem-react-helper';
export default class Block extends Component {
render() {
return (
<div className={b('block', this.props, { size: s })} />
);
}
}
With usage like this:
<Block mods={{visible: true, type: 'primary', size: 'xxl'}} mix="block2__elem"/>
You also can pass mix as an array:
<Block mods={{visible: true, type: 'primary', size: 'xxl'}} mix={['block2__elem', 'block3']}/>
And if you want to use mods or mix in a body of component, or pass other arguments, the best way to do that is:
import b from 'bem-react-helper';
export default class Block extends Component {
render() {
const { mix, mods = {}, ...rest } = this.props;
return (
<div className={b('block', this.props, { size: s })} {...rest}>
{
mods.type === 'primary' &&
(
<span className="block__star">★</span>
)
}
</div>
);
}
}
Why didn't I use all of others helpers and created yet another one? They bloat code but don't do anything useful. Also I believe that write plain classes is faster than use any wrappers around it.
So this helper solves just one problem (the main, I think) — it removes conditions for modifiers and mixes in block's declaration.
FAQs
Allows you to easily manage BEM mods & mixes in React
The npm package bem-react-helper receives a total of 104 weekly downloads. As such, bem-react-helper popularity was classified as not popular.
We found that bem-react-helper 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.