. - currying, , this.props . , handleChangeDecadeStart - :
const handleChangeDecadeStart = props => (datePickerId, value) => {
const currentDecadeStart = this.props.decadeStart;
if(value === "prev") {
return this.props.actions.setDecadeStart(datePickerId,
currentDecadeStart - 10);
} else {
return this.props.actions.setDecadeStart(datePickerId,
currentDecadeStart + 10);
}
}
:
return (
<YourComponent onChangeDecadeStart={handleChangeDecadeStart(this.props)}/>
)
, this.props, .
, React :
connect(mapStateToProps, mapDispatchToProps)(MyReactComponent)
, , , - . HOC - , , , .
:
const wrapWithHandlers = Component => class Wrapper extends Component {
handleChangeDecadeStart = (datePickerId, value) => {
const currentDecadeStart = this.props.decadeStart;
if(value === "prev") {
return this.props.actions.setDecadeStart(datePickerId, currentDecadeStart - 10);
} else {
return this.props.actions.setDecadeStart(datePickerId, currentDecadeStart + 10);
}
}
render() {
return <Component onChangeDecadeStart={this.handleChangeDecadeStart} {...this.props} />
}
}
- :
export default wrapWithHandlers(MyComponent)
, , . , , , :
export default connect(mapStateToProps, mapDispatchToProps)(wrapWithHandlers(MyComponent))
, , .., , , :
import { compose } from 'redux'
...
const enhancer = compose(connect(mapStateToProps, mapDispatchToProps), wrapWithHandlers);
export default enhancer(MyComponent);
, , , HOC , recompose . withHandlers, .