Research
Security News
Kill Switch Hidden in npm Packages Typosquatting Chalk and Chokidar
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
babel-plugin-stateful-functional-react-components
Advanced tools
Stateful functional React components without runtime overhead
✨ Stateful functional React components without runtime overhead (inspired by ClojureScript) ✨
Compiles stateful functional React components syntax into ES2015 classes
WARNING: This plugin is experimental. If you are interested in taking this further, please open an issue or submit a PR with improvements.
Because functional components are concise and it's annoying to write ES2015 classes when all you need is local state.
Input
// props context state init state
const Counter = ({ text }, { theme }, { val } = { val: 0 }, setState) => (
<div className={theme}>
<h1>{text}</h1>
<div>
<button onClick={() => setState({ val: val - 1 })}>-</button>
<span>{val}</span>
<button onClick={() => setState({ val: val + 1 })}>+</button>
</div>
</div>
);
Output
class Counter extends React.Component {
constructor() {
super();
this.state = { val: 0 };
}
render() {
const { text } = this.props;
const { theme } = this.context;
const { val } = this.state;
return (
<div className={theme}>
<h1>{text}</h1>
<div>
<button onClick={() => this.setState({ val: val - 1 })}>-</button>
<span>{val}</span>
<button onClick={() => this.setState({ val: val + 1 })}>+</button>
</div>
</div>
);
}
}
(props [,context], state = initialState, setState)
props
is component’s props i.e. this.props
context
is optional parameter which corresponds to React’s contextstate
is component’s state, initialState
is requiredsetState
maps to this.setState
setState
npm i babel-plugin-stateful-functional-react-components
.babelrc
{
"plugins": ["stateful-functional-react-components"]
}
babel --plugins stateful-functional-react-components script.js
require("babel-core").transform("code", {
plugins: ["stateful-functional-react-components"]
});
MIT
FAQs
Stateful functional React components without runtime overhead
The npm package babel-plugin-stateful-functional-react-components receives a total of 1 weekly downloads. As such, babel-plugin-stateful-functional-react-components popularity was classified as not popular.
We found that babel-plugin-stateful-functional-react-components 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 researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.