Enterprise-grade offline
synchronization for React.
Building offline-first apps is hard. This library handles the complexity of queueing mutations to IndexedDB, managing auto-sync, and handling smart retries so you don't have to.
Architecture Simulator
Experience how the library manages data flow. Toggle the Network Status to see how requests are handled differently when Online vs. Offline. Watch the Queue populate when offline and flush when connection restores.
Smart Retries Logic
When the server returns a 5xx error, the engine doesn't spam the API. It uses Exponential Backoff to increase the delay between attempts, capped at 30 seconds.
Why IndexedDB?
Unlike localStorage (which is blocking and limited to ~5MB), this library uses IndexedDB. This ensures your main thread stays responsive even with large queues.
No Blocking
Runs independently of React render cycle.
Auto-Sync
Listens to window.onLine events automatically.
Type-Safe
Full TypeScript definitions included.
Auth Ready
Inject fresh tokens before sync.
Integration Guide
Implementation is a two-step process: Wrap your app with the Provider, then use the Hook. Toggle the tabs below to see the code.
// App.tsx
import React from 'react';
import { OfflineSyncProvider } from '@imirfanul/react-offline-sync';
import MyComponent from './MyComponent';
const App = () => {
return (
// Wraps the entire application context
<OfflineSyncProvider>
<MyComponent />
</OfflineSyncProvider>
);
};
export default App;
API Reference
Detailed breakdown of props and return values.
<OfflineSyncProvider />
-
prepareHeadersAsync FunctionInjects headers (like Auth tokens) just before the request executes.
-
onSuccessCallbackFired when a queued request successfully syncs with the server.
-
onErrorCallbackFired on permanent failure (e.g., 400 Bad Request).
useOfflineMutation()
Returns a submit function.
- body: JSON payload
- options.url: Endpoint URL
- options.method: POST | PUT | PATCH | DELETE