Created
July 29, 2019 11:45
-
-
Save koss-lebedev/1ffbb7e990572abdef120275e5007c19 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from "react" | |
import { Quote } from "./canvas" | |
export function KanyeQuote() { | |
const [quote, setQuote] = React.useState("") | |
React.useEffect(() => { | |
// load quote from local storage if it's there, fetch from API otherwise | |
if (localStorage.getItem("quote")) { | |
setQuote(localStorage.getItem("quote")) | |
} else { | |
fetch("https://api.kanye.rest/").then(response => { | |
response.json().then(json => { | |
// store quote in local storage when it's first fetched | |
localStorage.setItem("quote", json.quote) | |
setQuote(json.quote) | |
}) | |
}) | |
} | |
}, []) | |
return <Quote text={quote} /> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment