
Security News
Django Joins curl in Pushing Back on AI Slop Security Reports
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
react-indexed-db
Advanced tools
react-indexed-db is a service that wraps IndexedDB database in an "easier to use" service. It exposes very simple promises API to enable the usage of IndexedDB without most of it plumbing.
npm install react-indexed-db
https://codesandbox.io/s/react-indexed-db-dmmci
Create a context with an DB:
import { IndexedDB } from 'react-indexed-db';
import PanelExample from './Panel';
const App: React.FC = () => {
return (
<IndexedDB
name="MyDB"
version={1}
objectStoresMeta={[
{
store: 'people',
storeConfig: { keyPath: 'id', autoIncrement: true },
storeSchema: [
{ name: 'name', keypath: 'name', options: { unique: false } },
{ name: 'email', keypath: 'email', options: { unique: false } }
]
}
]}>
<Panel />
</IndexedDB>
);
};
and in any component inside this context you can consume it like bellow:
import { AccessDB } from 'react-indexed-db';
export default function PanelExample() {
return (
<AccessDB objectStore="people">
{db => {
console.log('MyDB: ', db);
return <div>{JSON.stringify(db)}</div>;
}}
</AccessDB>
);
}
The first argument is the name of your database and the second is the database version. If you forget the version you the service will default to version 1.
Use the APIs that the ReactIndexedDB service exposes to use indexeddb. In the API the following functions:
Usage example:
<AccessDB objectStore="people">
{({ getByKey }) => {
const [person, setPerson] = useState(null);
getByKey('people', 1).then(
personFromDB => {
setPerson(personFromDB);
},
error => {
console.log(error);
}
);
return <div>{person}</div>;
}}
</AccessDB>
Usage example:
<AccessDB objectStore="people">
{({ getAll }) => {
const [persons, setPersons] = useState(null);
getAll().then(
peopleFromDB => {
setPersons(peopleFromDB);
},
error => {
console.log(error);
}
);
return <div>{persons}</div>;
}}
</AccessDB>
Usage example:
<AccessDB objectStore="people">
{({ getByIndex }) => {
const [person, setPerson] = useState(null);
getByIndex('name', 'Dave').then(
personFromDB => {
setPerson(peopleFromDB);
},
error => {
console.log(error);
}
);
return <div>{person}</div>;
}}
</AccessDB>
Usage example (add without a key):
<AccessDB objectStore="people">
{({ add }) => {
return (
<button
onClick={() => {
add({ name: 'name', email: 'email' }).then(
event => {
console.log('ID Generated: ', event.target.result);
},
error => {
console.log(error);
}
);
}}>
Add
</button>
);
}}
</AccessDB>
In the previous example I'm using undefined as the key because the key is configured in the objectStore as auto-generated.
Usage example (update without a key):
<AccessDB objectStore="people">
{({ update }) => {
return (
<button
onClick={() => {
update('people', { id: 3, name: 'name', email: 'email' }).then(
() => {
// Do something after update
},
error => {
console.log(error);
}
);
}}>
Update
</button>
);
}}
</AccessDB>
Usage example:
<AccessDB objectStore="people">
{({ deleteRecord }) => {
return (
<button
onClick={() => {
deleteRecord(3).then(
() => {
// Do something after delete
},
error => {
console.log(error);
}
);
}}>
Delete
</button>
);
}}
</AccessDB>
Usage example:
<AccessDB objectStore="people">
{({ openCursor }) => {
return (
<button
onClick={() => {
openCursor(evt => {
var cursor = evt.target.result;
if (cursor) {
console.log(cursor.value);
cursor.continue();
} else {
console.log('Entries all displayed.');
}
}, IDBKeyRange.bound('A', 'F'));
}}>
Run cursor
</button>
);
}}
</AccessDB>
Usage example:
<AccessDB>
{({ db }) => {
return (
<button
onClick={() => {
clear('people').then(
() => {
// Do something after clear
},
error => {
console.log(error);
}
);
}}>
Clear Table
</button>
);
}}
</AccessDB>
Released under the terms of the MIT License.
FAQs
React wrapper to IndexedDB database.
The npm package react-indexed-db receives a total of 792 weekly downloads. As such, react-indexed-db popularity was classified as not popular.
We found that react-indexed-db demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.