Doesn't work with decorator
See original GitHub issueI have the following code:
import React, { Component, PropTypes } from 'react';
import LinkedStateMixin from 'react-addons-linked-state-mixin';
import ReactMixin from 'react-mixin';
import s from './LoginPage.scss';
import withStyles from '../../decorators/withStyles';
const title = 'Log In';
@withStyles(s)
class LoginPage extends Component {
constructor() {
super();
this.state = {
user: '',
password: ''
}
}
static contextTypes = {
onSetTitle: PropTypes.func.isRequired,
};
componentWillMount() {
this.context.onSetTitle(title);
}
login(e) {
e.preventDefault();
console.log(e)
}
render() {
return (
<div className={s.root}>
<div className={s.container}>
<h1>{title}</h1>
<form role="role">
<div>
<label>
Email
</label>
<input type="email" valueLink={this.linkState('email')} placeholder="email" />
</div>
<div>
<label>
Password
</label>
<input type="password" valueLink={this.linkState('password')} placeholder="password" />
</div>
<button type="submit" onClick={this.login.bind(this)}>Login</button>
<p>
Forgot your password?
</p>
</form>
</div>
</div>
);
}
}
ReactMixin(LoginPage.prototype, LinkedStateMixin);
export default LoginPage
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’
Issue Analytics
- State:
- Created 8 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
python decorator doesn't work - Stack Overflow
I am new to python. I want to pass the arguments to a class derorator: class TestClass(object): def __init__( ...
Read more >Parameter decorator doesn't work when applying to symbol ...
I find that I cannot use parameter decorators on symbol methods. In ts-node it results in target[key] being undefined , while on the...
Read more >Code Completion doesn't work for (class) functions decorated ...
Code Completion doesn't work for (class) functions decorated with decorators that return inner functions Follow.
Read more >Please Fix Your Decorators - Hynek Schlawack
If your Python decorator unintentionally changes the signatures of my callables or doesn't work with class methods, it's broken and should ...
Read more >Primer on Python Decorators
The problem is that the inner function wrapper_do_twice() does not take any arguments, but name="World" was passed to it. You could fix this...
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 FreeTop 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
Top GitHub Comments
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.
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:
routerWillLeave
method is provided from mixin. If you useReact.createClass
, all methods are bond to this class by default. And you can use it inrender
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 addsrouterWillLeave
. 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.