Created
March 24, 2018 21:08
-
-
Save davidyeiser/cfa45d69ce6da47a74ffcffb66494b01 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
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