Skip to content

RTK: selectors and type inferring #3380

Answered by EskiMojo14
dakur asked this question in Q&A
Discussion options

You must be logged in to vote

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;
  },
);

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@dakur
Comment options

@dakur
Comment options

@dakur
Comment options

Answer selected by EskiMojo14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants