Skip to content

Instantly share code, notes, and snippets.

@codemile
Created August 13, 2021 15:15
Show Gist options
  • Save codemile/77361fa9fc051f0b3817edb2929488c8 to your computer and use it in GitHub Desktop.
Save codemile/77361fa9fc051f0b3817edb2929488c8 to your computer and use it in GitHub Desktop.
Hook that fetches a random Games Of Thrones quote.
import {useEffect, useState} from 'react';
const useGotQuote = () => {
const [quote, setQuote] = useState('');
useEffect(() => {
fetch('https://game-of-thrones-quotes.herokuapp.com/v1/random')
.then((response) => response.json())
.then((data) => setQuote(data?.sentence));
}, []);
return quote;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment