import * as React from 'react'; import { IRootState } from '../store'; import { connect } from 'react-redux'; import { Dispatch } from 'redux'; import * as actions from '../store/demo/actions'; import { DemoActions } from '../store/demo/types'; import { Input, Button, Col, Row } from 'antd'; const mapStateToProps = ({ demo }: IRootState) => { const { list } = demo; return { list }; } const mapDispatcherToProps = (dispatch: Dispatch) => { return { addItem: (item: string) => dispatch(actions.addItemToList(item)) } } type ReduxType = ReturnType & ReturnType; interface IState { text: string } class Home extends React.Component { public state: IState = { text: '' } private renderItem = (item: string) => { return (
{item}
) } private onTextChange = (event: React.ChangeEvent) => { this.setState({text: event.target.value}); } private onAdd = () => { this.props.addItem(this.state.text); this.setState({text: ''}); } public render() { const {list} = this.props; const {text} = this.state; return (

Home

{list.map(this.renderItem)}
); } } export default connect(mapStateToProps, mapDispatcherToProps)(Home);