-
Notifications
You must be signed in to change notification settings - Fork 704
Expand file tree
/
Copy pathPostsList.js
More file actions
36 lines (33 loc) · 842 Bytes
/
PostsList.js
File metadata and controls
36 lines (33 loc) · 842 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import PostsExcerpt from "./PostsExcerpt";
import { useGetPostsQuery } from './postsSlice';
const PostsList = () => {
const {
postsIds,
isLoading,
isSuccess,
isError,
error
} = useGetPostsQuery('getPosts', {
selectFromResult: ({ data, isLoading, isSuccess, isError, error }) => ({
postsIds: data?.ids,
isLoading,
isSuccess,
isError,
error,
}),
})
let content;
if (isLoading) {
content = <p>"Loading..."</p>;
} else if (isSuccess) {
content = postsIds?.map(postId => <PostsExcerpt key={postId} postId={postId} />)
} else if (isError) {
content = <p>{error}</p>;
}
return (
<section>
{content}
</section>
)
}
export default PostsList