I have some code as below
var React = require('react');
var Controls = React.createClass({
propTypes: {
countdownStatus: React.PropTypes.string.isRequired,
onStatusChange: React.PropTypes.func.isRequired
},
onStatusChange(newStatus) {
return ()=>{
this.props.onStatusChange(newStatus);
}
// this.props.onStatusChange(newStatus);
},
render() {
var {countdownStatus} = this.props;
var renderStartStopButton = ()=>{
if(countdownStatus == 'started') {
return (
<button className="button secondary"
onClick={this.onStatusChange('paused')}
>Pause</button>
)
} else if(countdownStatus == 'paused') {
return (
<button className="button primary"
onClick={this.onStatusChange('started')}
>Start</button>
)
}
}
return(
<div className="controls">
{renderStartStopButton()}
<button className="button alert hollow"
onClick={this.onStatusChange('stopped')}
>Clear</button>
</div>
)
}
})
module.exports = Controls;
My question is in the function of onStatusChange(newStatus), It will be wrong to use the commented statement other than return an anonymous function. But I can not get what is the difference between return a function and call the function directly.
Anyone could please help to explain the difference? thank you very much!