From 894d1856e504536ecd73a91a6dd763e91cd5bed0 Mon Sep 17 00:00:00 2001 From: pratap360 Date: Thu, 16 Oct 2025 14:46:37 +0530 Subject: [PATCH] fixed the quote genration --- src/pages/JokesQuotes.jsx | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/pages/JokesQuotes.jsx b/src/pages/JokesQuotes.jsx index 409aa94..08c7bcf 100644 --- a/src/pages/JokesQuotes.jsx +++ b/src/pages/JokesQuotes.jsx @@ -40,15 +40,18 @@ export default function JokesQuotes() { setJoke(await res.json()); } catch (e) { setError(e); } finally { setLoading(false); } } - + async function fetchQuote() { - try { - setLoading(true); setError(null); - const res = await fetch('https://api.quotable.io/random'); - if (!res.ok) throw new Error('Failed to fetch'); - setQuote(await res.json()); - } catch (e) { setError(e); } finally { setLoading(false); } - } + try { + setLoading(true); setError(null); + const res = await fetch('https://api.allorigins.win/get?url=' + encodeURIComponent('https://zenquotes.io/api/random')); + if (!res.ok) throw new Error('Failed to fetch'); + const data = await res.json(); + const quotes = JSON.parse(data.contents); + setQuote({content: quotes[0].q, author: quotes[0].a}); + } catch (e) { setError(e); } finally { setLoading(false); } +} + async function searchQuotes() { if (!search) return;