Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-class

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-class - npm Package Compare versions

Comparing version 3.0.1 to 3.1.0

autoBind.js

2

package.json
{
"name": "react-class",
"version": "3.0.1",
"version": "3.1.0",
"description": "A carefully crafted base class for all your React components ",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -37,14 +37,36 @@ # react-class

## auto-binding
## Just auto-binding
In order to get autobinding, just extend the class exported by `react-class`
If you don't want to extend the class exported by `react-class` and instead just want autobinding, you can just import the `autoBind` function directly.
```jsx
import 'react-class/autoBind'
var ReactClass = require('react-class');
// or
class App extends ReactClass { ... }
import { autoBind } from 'react-class'
// or
var autoBind = require('react-class/autoBind')
````
After importing/require-ing it, call `autoBind` in the component constructor:
```jsx
import autoBind from 'react-class/autoBind'
class MyApp extends React.Component {
constructor(props) {
super(props)
autoBind(this)
}
render() {
// ... your rendering logic
}
}
```
## FAQ

@@ -51,0 +73,0 @@

"use strict";
var React = require('react')
var autoBind = require('../autoBind')
var skipMethods = {
'constructor': 1,
'render': 1,
'shouldComponentUpdate': 1,
'componentWillMount': 1,
'componentDidMount': 1,
'componentWillReceiveProps': 1,
'componentWillUpdate': 1,
'componentDidUpdate': 1,
'componentWillUnmount': 1
}
function autoBind(object){
var proto = object.constructor.prototype
var names = Object.getOwnPropertyNames(proto).filter(function(key) {
return skipMethods[key] !== 1 && typeof proto[key] === 'function'
})
names.push('setState')
names.forEach(function(key){
object[key] = object[key].bind(object)
})
return object
}
class ReactClass extends React.Component {

@@ -33,0 +7,0 @@ constructor(props){

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc