Reputation: 3758
The functionality that I'm looking for works flawlessly here with the static function syntax, however, I like the static functions declared on the constructor itself (i.e. className.staticFunction () => ...
instead of static staticFunction = () => ...
within the class definition itself.
Here's the code I'm referring to that I'd like to refactor to use the static functions defined on the constructor/function rather than the static
syntax as seen below.
const higherOrderFunction = another => andAnother => class extends Component {
static functionName = {
test: React.PropTypes.object
};
constructor(props) {
super(props);
}
render() {
return <h1>Hello, World!</h1>;
}
};
export default higherOrderFunction;
Upvotes: 0
Views: 100
Reputation: 4375
The value of a class
is the same as the constructor function
you'd define without classes. So:
const higherOrderFunction = another => andAnother => Component;
function Component() {}
Component.functionName = () => {
test: React.PropTypes.object
};
Component.prototype.render = () => {
return <h1>Hello, World!</h1>;
}
export default higherOrderFunction;
You may want to wrap the function and member definitions in the function body to encapsulate and use any arguments:
const higherOrderFunction = another => andAnother => {
function Component() {}
Component.functionName = () => {
test: React.PropTypes.object
};
Component.prototype.render = () => {
return <h1>Hello, World! {another} and {andAnother}</h1>;
}
return Component;
};
export default higherOrderFunction;
Upvotes: 1