-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAllQuotes.jsx
45 lines (37 loc) · 1.04 KB
/
AllQuotes.jsx
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
37
38
39
40
41
42
43
44
45
import React, { useEffect } from "react";
import QuoteList from "../components/quotes/QuoteList";
import LoadingSpinner from "../components/UI/LoadingSpinner";
import NoQuotesFound from "../components/quotes/NoQuotesFound"
import useHttp from "../hooks/use-http";
import { getAllQuotes } from "../lib/api";
const Quotes_Example = [
{ id: "q1", author: "Max", text: "Learning React Router" },
{ id: "q2", author: "Stav", text: "Learning React Router2" },
];
function AllQuotes() {
const {
sendRequest,
status,
data: LoadedQuotes,
error,
} = useHttp(getAllQuotes, true);
useEffect(() => {
sendRequest();
}, [sendRequest]);
if (status === "pending") {
return (
<div className="centeres">
{" "}
<LoadingSpinner />
</div>
);
}
if (error) {
return <p className="centered focused">{error}</p>;
}
if (status === "completed" && (!LoadedQuotes || LoadedQuotes.length === 0)) {
return <NoQuotesFound/>
}
return <QuoteList quotes={LoadedQuotes} />;
}
export default AllQuotes;