我有一个带有 Redux 和几个createSelector 的ReactJS 应用程序,但我想更改其中一些。
以下是当前选择器的示例:
export const getAppData = createSelector(
(state: RootState): AppDataState => state[`appData-${getUniquishModuleId()}`],
(appData: AppDataState): AppDataState => appData,
);
export const getNextPageToRender = createSelector(
[
(state: RootState): PageSlug[] =>
state[`appData-${getUniquishModuleId()}`].pagesToRender,
(_: RootState, currentPageSlug: PageSlug): PageSlug => currentPageSlug,
],
(pagesToRender: PageSlug[], currentPageSlug: PageSlug): PageSlug => {
const currentPageIndex: number = pagesToRender.findIndex(
(page: PageSlug) => page === currentPageSlug
);
return pagesToRender[currentPageIndex + 1];
},
);
现在我想做的是getNextPageToRender
也使用getAppData
选择器。
我尝试过:
export const getNextPageToRender = createSelector(
getAppData,
[
(appData: AppDataState): PageSlug[] =>
getContextRelatedAppData(appData).pagesToRender,
(_: AppDataState, currentPageSlug: PageSlug): PageSlug => currentPageSlug,
],
(pagesToRender: PageSlug[], currentPageSlug: PageSlug): PageSlug => {
const currentPageIndex: number = pagesToRender.findIndex(
(page: PageSlug) => page === currentPageSlug
);
return pagesToRender[currentPageIndex + 1];
},
);
我也尝试过:
export const getNextPageToRender = createSelector(
[
getAppData,
(appData: AppDataState): PageSlug[] =>
getContextRelatedAppData(appData).pagesToRender,
(_: AppDataState, currentPageSlug: PageSlug): PageSlug => currentPageSlug,
],
(pagesToRender: PageSlug[], currentPageSlug: PageSlug): PageSlug => {
const currentPageIndex: number = pagesToRender.findIndex(
(page: PageSlug) => page === currentPageSlug
);
return pagesToRender[currentPageIndex + 1];
},
);
但这个语法好像不起作用。
有人可以帮忙吗?我做错了什么?