
Security News
The Hidden Blast Radius of the Axios Compromise
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.
babel-plugin-react-auto-binding
Advanced tools
Babel plugin for React component to take event handler to bind context automatically.
Babel plugin for React component to take event handler to bind context automatically.
$ npm install babel-plugin-react-auto-binding --save-dev
When you are building a React component, you have to be careful about event handler. In component, class methods are not bound by default. If you forget to bind this.handleClick and pass it to onClick, this will be undefined when the function is actually called.
Therefore, you have to bind the event handler in constructor method, like this,
class App extends React.Component{
constructor(props) {
super(props)
this.state = {
view: false
}
this.handleClick = this.handleClick.bind(this) // binding method
}
handleClick(e) {
this.setSate({
view: true
})
}
render() {
return (
<div>
<button onClick={this.handleClick}>Click me</button>
<br />
{
(view) && <div>React auto binding succeeded</div>
}
</div>
)
}
}
It's so troublesome. So, this plugin is born to resolve these thorny problems. With this plugin, you can easily code without caring about context.
Instead,
class App extends React.Component{
constructor(props) {
super(props)
this.state = {
view: false
}
// needn't binding method
}
handleClick(e) {
this.setSate({
view: 'value'
})
}
render() {
return (
<div>
<button onClick={this.handleClick}>Click me</button>
<br />
{
(view) && <div>React auto binding succeeded</div>
}
</div>
)
}
}
Write via babelrc.
// .babelrc
{
"plugins": [
"react-auto-binding"
]
}
This plugin check the spuerClass after the extends in classDeclaration to know whether it is React component or not.
Only supported React.Component, React.PureComponent, Component, PureComponent
Do not use other words instead of it, like this,
import {Component as ReactComponent} from "react"
class App extends ReactComponent{
//...
}
FAQs
Babel plugin for React component to take event handler to bind context automatically.
We found that babel-plugin-react-auto-binding 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
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.