RTK: selectors and type inferring #3380
-
Hi again, I need please some more help with typings in RTK, this time when defining selectors. This simple selector which takes advantage of import {createSelector} from '@reduxjs/toolkit';
function pages(state: State): Page[]
{
return state.material.pages;
}
function commentsFromAllPages(): Comment[][]
{
const out = createSelector(
[pages],
(pages) => {
const comments = pages.map((page) => page.comments);
return comments;
},
);
return out;
} But it's giving me strange typing error (notice also the type at the line with I've checked for generic arguments or something, but did not find anything.. Can you point me in some direction, please? Thanks in advance. |
Beta Was this translation helpful? Give feedback.
Answered by
EskiMojo14
Apr 18, 2023
Replies: 1 comment 3 replies
-
createSelector returns an instance of a selector. you should use it like this: import { createSelector } from '@reduxjs/toolkit';
function selectPages(state: State): Page[] {
return state.material.pages;
}
const selectCommentsFromAllPages = createSelector(
[selectPages],
(pages) => {
const comments = pages.map((page) => page.comments);
return comments;
},
); |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
EskiMojo14
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
createSelector returns an instance of a selector. you should use it like this: