Suppose I have a ReactJS component and want to call some custom function in it, is it better to have this function as a class method, or rather defined separately? (suppose that the function should be used only in this component)
class OnwComponent extends React.Component {
constructor() {
super();
this.doubledNumber = this.doubledNumber.bind(this);
}
doubledNumber(num) {
return num * 2;
}
render() {
return (
<p>{doubledNumber(10)} or {this.doubledNumber(10)}? Pros and cons?
);
}
}
function doubledNumber(num) {
return num * 2;
}
this, there is no need to.bindit in the constructor or for it to be a class method.