Closed
Description
In writing a custom propTypes
validation function, I would like to be able to access mixins, for shared validation behavior.
Given the following mixin:
var MyMixin = {
nameValidation: function(){
console.log("won't be run...");
}
};
My goal would be that I could do the following:
var Hello = React.createClass({
mixins: [MyMixin],
propTypes: {
name: function(){
this.nameValidation();
}
},
render: function() {
return <div>Hello {this.props.name}</div>;
}
});
But this fails because this
is window
, not the instance. Is it possible to autobind propType functions?
Here is a jsfiddle of the above code (slightly modified): http://jsfiddle.net/kXysA/1/
For reference: I also tried the following, but I'm not surprised this failed because this
is undefined
in this context:
var Hello = React.createClass({
mixins: [MyMixin],
propTypes: {
name: this.nameValidation
},
render: function() {
return <div>Hello {this.props.name}</div>;
}
});
Metadata
Metadata
Assignees
Labels
No labels