Skip to content

Instantly share code, notes, and snippets.

@davidyeiser
Created March 24, 2018 21:08
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 davidyeiser/cfa45d69ce6da47a74ffcffb66494b01 to your computer and use it in GitHub Desktop.
Save davidyeiser/cfa45d69ce6da47a74ffcffb66494b01 to your computer and use it in GitHub Desktop.
componentDidMount() {
const cachedAirtableNotes = localStorage.getItem('_cachedAirtableNotes')
if (cachedAirtableNotes) {
// Local data exists, now let's see if it has "expired"
// parse data
const parsedAirtableNotes = JSON.parse(cachedAirtableNotes)
// Check current time against timestamp
if (new Date().getTime() > parsedAirtableNotes.timestamp) {
// Current time is past timestamp, therefore it's "expired"
this.getAirtableNotes()
}
else {
// Not "expired", use it
this.setState({ airtableNotes: JSON.parse(parsedAirtableNotes.data) })
}
}
else {
this.getAirtableNotes()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment