Skip to content

Commit ae89f51

Browse files
Merge pull request #70 from pratap360/main
fixed the quote generation
2 parents f47ee8c + 894d185 commit ae89f51

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

src/pages/JokesQuotes.jsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,18 @@ export default function JokesQuotes() {
4040
setJoke(await res.json());
4141
} catch (e) { setError(e); } finally { setLoading(false); }
4242
}
43-
43+
4444
async function fetchQuote() {
45-
try {
46-
setLoading(true); setError(null);
47-
const res = await fetch('https://api.quotable.io/random');
48-
if (!res.ok) throw new Error('Failed to fetch');
49-
setQuote(await res.json());
50-
} catch (e) { setError(e); } finally { setLoading(false); }
51-
}
45+
try {
46+
setLoading(true); setError(null);
47+
const res = await fetch('https://api.allorigins.win/get?url=' + encodeURIComponent('https://zenquotes.io/api/random'));
48+
if (!res.ok) throw new Error('Failed to fetch');
49+
const data = await res.json();
50+
const quotes = JSON.parse(data.contents);
51+
setQuote({content: quotes[0].q, author: quotes[0].a});
52+
} catch (e) { setError(e); } finally { setLoading(false); }
53+
}
54+
5255

5356
async function searchQuotes() {
5457
if (!search) return;

0 commit comments

Comments
 (0)