02_lesson: create separate selector for selectAllPosts

02_lesson
Jason Zhu 2023-03-06 21:31:34 +11:00
parent 365bfa6db4
commit 0ea7837958
2 changed files with 4 additions and 1 deletions

View File

@ -1,7 +1,8 @@
import { useSelector } from "react-redux"; import { useSelector } from "react-redux";
import { selectAllPosts } from "./postsSlice";
const PostsList = () => { const PostsList = () => {
const posts = useSelector((state) => state.posts); const posts = useSelector(selectAllPosts);
const renderedPosts = posts.map((post) => ( const renderedPosts = posts.map((post) => (
<article key={post.id}> <article key={post.id}>

View File

@ -19,4 +19,6 @@ const postsSlice = createSlice({
reducers: {}, reducers: {},
}); });
export const selectAllPosts = (state) => state.posts;
export default postsSlice.reducer; export default postsSlice.reducer;