Skip to content

For all methods, binds 'this' to the React component created with class extends. Without it 'this' refers to 'Window'.

License

Notifications You must be signed in to change notification settings

steinitz/Meteor-React-ES6-AutoBind

 
 

Repository files navigation

#Adds a method to bind 'this' to the component

If you create your React component with React.createClass most of your methods are automatically bound (as expected) such that 'this' refers to the component itself rather than 'window'. This package allows you to do the same for ES6 React Components, i.e. React Components created as follows:

MyReactComponent = class MyReactComponent extends React.Component

To accomplish this automatic binding in ES6 classes, install the package, then call SteinitzREA.Autobind in your class's constructor, like this:.

MyReactComponent = class MyReactComponent extends React.Component
{
    constructor (props)
    {
        super (props);
        SteinitzREA.AutoBind (this);
    }
    ...

Note that my main purpose for releasing this package was to support my React ES6 Component package (which calls AutoBind for you in its own constructor). But I felt that this package might be useful to someone on it's own. Personally, I found it annoying to that 'this' pointed to 'window' in most React ES6 class methods. And, Facebook have stated that they have no intention of changing that.

About

For all methods, binds 'this' to the React component created with class extends. Without it 'this' refers to 'Window'.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%