react-class-binder
react-class-binder copied to clipboard
How does this handle child classes?
Hi!
I was just wondering if I had to add the binder mixin on child classes. Let's say I have an abstract parent classes that extends React.Component
, then children that derive. Do I need to add the binder mixin to the children as well as the parents, or just the parent?
This module is very careful to only apply to the "current" class.
That means that you will need to apply it to every single class you want to use it in, regardless of if it extends a class that has it applied.
This was to prevent any issues overwriting this
for classes you extend.
Thanks for the quick response.
I'm running into issues binding a child class where I extend a generic parent component.
My parent looks something like this:
export default class DataComponent extends binder(React.Component) {
getRepository(): void { // }
}
Child:
export default class ChildComponent extends binder(DataComponent) {
onChildComponent(component) {
this.component = component;
}
//
}
However, I had an error on onChildComponent
- this was undefined
.
Any ideas? I'm binding both parent and child classes.
Ugh, honestly I'm not sure... I'm actually on vacation for a week currently, so I won't be able to look at this until like Oct 3rd or later.
I'll reopen this for now.
Sure thing. For now I'm just not using the parent. Let me know when you get back if you want to see the exact code, I have it hosted and can share.
Bump? Any movement on this?
Sorry, but not really. I looked into what is going on and I can't seem to pinpoint why it's not working. I think there is some interaction with the prototypes that i'm not understanding.
Hmm okay. Maybe if I get a chance I'll dig in, take a look for myself? If I do I'll be sure to submit a PR!