【发布时间】:2019-05-26 13:56:37
【问题描述】:
我试图了解重新选择方法 createStructuredSelector 在 Typescript 中的工作原理。我经常看到这种模式:
export interface SomeProps {
readonly property1: string;
readonly property2: boolean;
readonly property3: number;
}
export interface SomeOwnProps {
readonly property3: number;
}
export const someSelector = createStructuredSelector<
SomeState,
SomeOwnProps,
SomeProps
>({
property1: property1Selector,
property2: property2Selector,
property3: (_, props) => props.property3
});
我不明白尖括号内的类型的用途。我认为SomeState是Redux store state,SomeOwnProps是父组件传入的props,SomeProps是这个组件使用的所有props。但是SomeOwnProps 和SomeProps 有什么区别,为什么两者都需要?为什么不能只使用SomeProps,因为它还包含SomeOwnProps 中定义的属性?谢谢!
【问题讨论】:
标签: reactjs typescript react-native redux reselect