有一个组件,但是来自 redux store 的数据不同,UI 是一样的,只是改变了数据的来源我使用 useSelector,所以我通过 props 传递选择器。
@types/leaflet
选择器
Argument of type 'OutputSelector<MergeStateI, GrocerieResponse[], (res: GroceriesInitStateI) => GrocerieResponse[]> | OutputSelector<...>' is not assignable to parameter of type '(state: MergeStateI) => GrocerieResponse[]'.
Type 'OutputSelector<MergeStateI, AgencyResponse[], (res: AgenciesInitStateI) => AgencyResponse[]>' is not assignable to type '(state: MergeStateI) => GrocerieResponse[]'.
Type 'AgencyResponse[]' is not assignable to type 'GrocerieResponse[]'.
Property 'grocerieImages' is missing in type 'AgencyResponse' but required in type 'GrocerieResponse'.
组件
export const selectFavoriteGroceries = createSelector(
[selectGroceries],
(groceries: GroceriesInitStateI) => groceries.favoriteGroceries
);
export const selectFavoriteAgencies = createSelector(
[selectAgencies],
(agencies: AgenciesInitStateI) => agencies.favoriteAgencies
);
答案 0 :(得分:0)
我不会通过 props 传递选择器函数,而是选择父组件中的数据,并将该数据作为 prop 传递。