如何替换mapStateToProps来hook useSelector?



如何替换mapStateToProps代码来hook useSelector?我以前从来没有使用过redux,我很难理解它。


interface BasicProductMarksListOwnProps {
productMarks: MarkResult[];
}
interface BasicProductMarksListStore {
productMarksState: AdditionalFilterState;
}
interface BasicProductMarksListActions {
onProductMarkChange: (productMarkGroupId: GenericId, isActive: boolean) => 
() => void;
}
export type BasicProductMarksListProps = BasicProductMarksListOwnProps 
& BasicProductMarksListStore & BasicProductMarksListActions;

const mapStateToProps: MapStateToProps<BasicProductMarksListStore, 
BasicProductMarksListOwnProps, ApplicationState> = (state) => ({
productMarksState: productMarksGroupStateSelector(state),
});

根据您提供的代码,我认为以下代码可以工作:

const productMarks = useSelector(state => productMarksGroupStateSelector(state)).

确保在功能组件中执行上面的代码。

最新更新