Skip to content

Instantly share code, notes, and snippets.

@koss-lebedev
Created July 29, 2019 11:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koss-lebedev/1ffbb7e990572abdef120275e5007c19 to your computer and use it in GitHub Desktop.
Save koss-lebedev/1ffbb7e990572abdef120275e5007c19 to your computer and use it in GitHub Desktop.
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