Gathering detailed insights and metrics for babel-plugin-react-auto-binding
Gathering detailed insights and metrics for babel-plugin-react-auto-binding
npm install babel-plugin-react-auto-binding
Typescript
Module System
Node Version
NPM Version
70.2
Supply Chain
99.3
Quality
75.3
Maintenance
100
Vulnerability
100
License
JavaScript (93.31%)
HTML (3.57%)
CSS (3.12%)
Total Downloads
13,183
Last Day
2
Last Week
9
Last Month
35
Last Year
246
1 Stars
7 Commits
1 Watching
1 Branches
1 Contributors
Minified
Minified + Gzipped
Latest Version
1.0.5
Package Id
babel-plugin-react-auto-binding@1.0.5
Unpacked Size
14.96 kB
Size
4.95 kB
File Count
14
NPM Version
5.5.1
Node Version
8.9.3
Cumulative downloads
Total Downloads
Last day
0%
2
Compared to previous day
Last week
-43.8%
9
Compared to previous week
Last month
150%
35
Compared to previous month
Last year
-65.7%
246
Compared to previous year
36
Babel plugin for React component to take event handler to bind context automatically.
1$ 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,
1class App extends React.Component{ 2 constructor(props) { 3 super(props) 4 this.state = { 5 view: false 6 } 7 this.handleClick = this.handleClick.bind(this) // binding method 8 } 9 handleClick(e) { 10 this.setSate({ 11 view: true 12 }) 13 } 14 render() { 15 return ( 16 <div> 17 <button onClick={this.handleClick}>Click me</button> 18 <br /> 19 { 20 (view) && <div>React auto binding succeeded</div> 21 } 22 </div> 23 ) 24 } 25} 26
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,
1class App extends React.Component{ 2 constructor(props) { 3 super(props) 4 this.state = { 5 view: false 6 } 7 // needn't binding method 8 } 9 10 handleClick(e) { 11 this.setSate({ 12 view: 'value' 13 }) 14 } 15 render() { 16 return ( 17 <div> 18 <button onClick={this.handleClick}>Click me</button> 19 <br /> 20 { 21 (view) && <div>React auto binding succeeded</div> 22 } 23 </div> 24 ) 25 } 26}
Write via babelrc.
1// .babelrc 2{ 3 "plugins": [ 4 "react-auto-binding" 5 ] 6} 7
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,
1import {Component as ReactComponent} from "react" 2 3class App extends ReactComponent{ 4 //... 5}
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no SAST tool detected
Details
Reason
Found 0/7 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
license file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
77 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More