![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
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 715 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
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.