Originally published at muhammadmoiz.dev .
IndexedDB is the browser's built-in database. It is the right place to keep the data a React app needs to keep working when the network drops. You can use it directly through a small wrapper like idb for simple caching. If you need relations, reactive queries and two-way sync with a server, put WatermelonDB on top of it. This tutorial walks through both approaches, with code you can adapt.
I used WatermelonDB on browser storage to build the offline-first data layer of Oscar, a restaurant and retail POS. A POS can't stop taking orders just because the Wi-Fi went down. The patterns below are the ones I'd reach for again. If you want the product-level story first, read lessons from building an offline-first POS in React . This post is the hands-on developer version.
What is IndexedDB, and why not just use localStorage?
IndexedDB is an asynchronous, transactional object store that ships with every modern browser. You don't define tables with fixed columns.…