A queue system for handling HTTP requests in React Native when the device is offline.
- Stores offline requests when there is no connection.
- Automatically retries requests when the connection is restored.
- Uses AsyncStorage for data persistence.
- Compatible with React Native and Expo.
Install the library with:
npm install react-native-offline-handler
# or
yarn add react-native-offline-handlerAlso, make sure you have the following dependencies installed:
yarn add @react-native-async-storage/async-storage @react-native-community/netinfo cross-fetchImport and use fetchWithQueue in your code:
import { fetchWithQueue } from "react-native-offline-handler";
const sendData = async () => {
await fetchWithQueue("https://api.example.com/data", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ key: "value" })
});
};- When the device is online,
fetchWithQueuesends the request normally. - If the device is offline, the request is stored in
AsyncStorage. - When the connection is restored, the queued requests are automatically processed.
The system monitors connection changes using NetInfo, retrying stored requests when the device is back online.
MIT
💡 Feel free to contribute and improve this library! 🚀