Skip to content

Instantly share code, notes, and snippets.

@tofusoup429
Last active June 4, 2020 05:54
Show Gist options
  • Save tofusoup429/cf76b77aff7593d562f53bebed0dcd87 to your computer and use it in GitHub Desktop.
Save tofusoup429/cf76b77aff7593d562f53bebed0dcd87 to your computer and use it in GitHub Desktop.
React.useEffect(()=>{
let openRequest = indexedDB.open("testingIndexedDB", 1);
openRequest.onupgradeneeded = function() {
// triggers if the client had no database or the client has a higher version
// ...perform initialization...
console.log("onupgradeneeded");
let db = openRequest.result;
console.log(db)
};
openRequest.onerror = function() {
console.error("Error", openRequest.error);
};
openRequest.onsuccess = function() {
let db = openRequest.result;
console.log(db);
console.log('database is ready');
// continue to work with database using db object
};
},[]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment