Answer the question
In order to leave comments, you need to log in
How to correctly use selectors from entityAdapters in redux-toolkit?
Created the post entity
const postsAdapter = createEntityAdapter({
selectId: (post) => post.postId,
});
const feedSlice = createSlice({
name: 'feed',
initialState: {
posts: postsAdapter.getInitialState(),
lastPostId: undefined,
loading: true,
error: false,
},
reducers: {
postUpdate: (state, { payload }) => {
postsAdapter.updateOne(state.posts, payload);
},
},
});
export const postsSelector = postsAdapter
.getSelectors(({ feed }) => feed.posts);
const post = useSelector((state) => postsSelector.selectById(state, postId));
const postsIds = useSelector((state) => postsSelector.selectIds(state));
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question