From 0ea7837958e8862cc45af9bb5208f40d00b80929 Mon Sep 17 00:00:00 2001 From: Jason Zhu Date: Mon, 6 Mar 2023 21:31:34 +1100 Subject: [PATCH] 02_lesson: create separate selector for selectAllPosts --- 02_lesson_starter/src/features/posts/PostsList.js | 3 ++- 02_lesson_starter/src/features/posts/postsSlice.js | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/02_lesson_starter/src/features/posts/PostsList.js b/02_lesson_starter/src/features/posts/PostsList.js index 817ac40..b30ec33 100644 --- a/02_lesson_starter/src/features/posts/PostsList.js +++ b/02_lesson_starter/src/features/posts/PostsList.js @@ -1,7 +1,8 @@ import { useSelector } from "react-redux"; +import { selectAllPosts } from "./postsSlice"; const PostsList = () => { - const posts = useSelector((state) => state.posts); + const posts = useSelector(selectAllPosts); const renderedPosts = posts.map((post) => (
diff --git a/02_lesson_starter/src/features/posts/postsSlice.js b/02_lesson_starter/src/features/posts/postsSlice.js index 989fbf5..e0efeb5 100644 --- a/02_lesson_starter/src/features/posts/postsSlice.js +++ b/02_lesson_starter/src/features/posts/postsSlice.js @@ -19,4 +19,6 @@ const postsSlice = createSlice({ reducers: {}, }); +export const selectAllPosts = (state) => state.posts; + export default postsSlice.reducer;