File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ;
You can’t perform that action at this time.
0 commit comments