Autobind decorator
See original GitHub issueI want to use autobind decorator for components.
This https://github.com/andreypopp/autobind-decorator/blob/master/src/index.js work fine with React (method binding). But have issue with RHL. Decorator bind method to instance. When new RHL add new prototype to prototype chain nothing happened, because method already in instance and new method in proto not visible when getter called.
I use ugly hack and check in getter if (this.props) to determine is this – instance.
It is not an issue with RHL or decorator itself. I try to find nice solution.
Issue Analytics
- State:
- Created 8 years ago
- Comments:26 (11 by maintainers)
Top Results From Across the Web
autobind-decorator - npm
Decorator for binding method to an object. Latest version: 2.4.0, last published: 4 years ago. Start using autobind-decorator in your ...
Read more >andreypopp/autobind-decorator - GitHub
autobind decorator. A class or method decorator which binds methods to the instance so this is always correct, even when the method is...
Read more >Working of a Autobind Decorator in typescript? - Stack Overflow
Autobind Decorator is an NPM package which binds methods of a class to the correct instance of this , even when the methods...
Read more >React & Autobinding - Medium
Autobind Decorator is an NPM package which binds methods of a class to the correct instance of `this`, even when the methods are...
Read more >AutoBind TypeScript decorator - Code Review Stack Exchange
The idea. So first of all, about the idea. Technically it is nice to auto-bind methods and use them without worrying about the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I don’t think this is fully working with
react-hot-loader@3.0.0-beta.2yet.Small test commit here.
In the demo above there’s 3 steps:
@autobindononClick, click the button. This doesn’t have the right context -thisisnull.@autobindtoonClick- this is recognized by RHL and correct logs the right state in the console (thisis bound to theCounterinstance).@autobind,thisis still bound to theCounterinstance (you would expect it not to be).RHL doesn’t remove the binding when using fat arrows to declare the method either.
Hope that’s helpful, would really love to use this with RHL!
For me this issue not actual now. I switch to arrow functions in class definition.
Can I close this issue?