/// import * as React from 'react'; import { connect } from 'react-redux'; import { reduxify } from './core'; interface IHelloWorldProps { field: string; step?: number; counter?: number; incr?: Function; decr?: Function; } @reduxify( (state, props) => ({ counter: (state[props.field] || 0) }), (dispatch) => ({ incr: (field, step) => { dispatch({ type: 'COUNTER_CHANGE', field, by: step }); }, decr: (field, step) => { dispatch({ type: 'COUNTER_CHANGE', field, by: -1 * step }); } }) ) export default class Counter extends React.Component { render() { var field = this.props.field, step = this.props.step || 1; return ( {field}: {this.props.counter} this.props.decr(field, step) }>- this.props.incr(field, step) }>+ ); } }
{field}: {this.props.counter}