import React, { FC } from ‘react’;
import { connect, ConnectedComponent, MapStateToPropsFactory, } from ‘react-redux’;
import { Dispatch } from ‘redux’;
import { ICounterAction } from ‘…/store’
export interface IPropsFromParent {
name: string;
}
export interface IPropsFromRedux {
count: number;
}
export interface IProps extends IPropsFromParent, IPropsFromRedux, ReturnType{};
/**
- FC 这个any 确定无法找到合适的定义
- @param props
*/
export const demo2: FC = (props: IProps) => {
return (
<>
name: {props.name}
age: {props.count}
加
减
</>
);
}
const mapStateToProps = (state: {count: number}, ownProps: IPropsFromParent) => {
return {
count: state.count
}
};
/**
*
- @param dispatch
- @param ownProps
- @UsageNotes
接口说明
-
- interface ICounterAction {
-
type: 'ADD'|'DESC', payload: number
- }
-
*/
const mapDispatchToProps = (dispatch: Dispatch, ownProps: IPropsFromParent) => {
return {
add: () => dispatch({type: “ADD”, payload: 1}),
desc: () => dispatch({type: “DESC”, payload: 1})
}
}
export const Demo2: ConnectedComponent<FC, IPropsFromParent> = connect(mapStateToProps, mapDispatchToProps)(demo2);