Open keatz55 opened 8 years ago
Does it work when you put the react-mixin decorator under the withStyles?
@withStyles(s)
@reactMixin.decorate(LinkedStateMixin)
class LoginPage extends Component {
Have the same issue. This is because when any code executes, its context doesn't match the class. Here, I suppose, must be a bind statement, that will explicitly set the context to decorated functions.
@Lonelind can you try to create a minimal repro case?
Sure.
For example, we could get a Lifecycle mixin form react-router v1.x (in 2.x mixins are deprecated). That's what I faced:
import React from 'react';
import { decorate as mixin } from 'react-mixin';
import { Lifecycle } from 'react-router';
@mixin(Lifecycle)
export default class RouteComponent extends React.Component {
routerWillLeave(nextRoute) {
console.log(this.state, this); // 'this' will be an anonymous function
}
render() {
/* ... */
}
}
routerWillLeave
method is provided from mixin. If you use React.createClass
, all methods are bond to this class by default. And you can use it in render
just like <div onClick={this.handleClick} />
. But if you use ES6 classes, NOTHING will be bond and you should bind every method by yourself. The same happens when mixin adds routerWillLeave
. Everything should be bond to class explicitly. So, maybe this is responsibility of mixin maker, and if so, your solution won't work if there weren't any explicit binding.
So the lack of autobinding in react-mixin strikes again... it's in the readme that it's not supported, but maybe it's time to support it.
I have the following code:
The react-mixin functionality works as intended without a decorator, however, when a decorator is included I get the error "this.linkState is not a function'