
Security News
Feross on Risky Business Weekly Podcast: npm’s Ongoing Supply Chain Attacks
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
offline-sync-handler-test
Advanced tools
Offline Sync Provider - README
Offline Sync Provider is a JavaScript module designed to handle API requests in web applications with offline capabilities. It offers a robust solution to synchronize data with the server even when the device is offline and automatically retries failed requests upon reconnection. This module utilizes axios
for making API requests and localforage
for offline storage, ensuring data integrity and smooth synchronization.
$ npm install --save offline-sync-handler
$ yarn add offline-sync-handler
You can find the working demo here
Wrap your application with the OfflineSyncProvider
component to enable offline sync and manage data synchronization.
import { OfflineSyncProvider } from 'offline-sync-handler';
const App = () => {
// Your application components and logic
};
const rootElement = document.getElementById('root');
ReactDOM.render(
<OfflineSyncProvider>
<App />
</OfflineSyncProvider>,
rootElement
);
You can use the sendRequest
function to send API requests. It handles retries in case of failure due to an unstable internet connection.
Refer to the axios-create
documentation for available config options.
import { useOfflineSyncContext } from from 'offline-sync-handler';
const { sendRequest } = useOfflineSyncContext();
const config = {
method: 'POST',
url: 'https://api.example.com/data',
data: { name: 'John Doe', email: 'john@example.com' },
};
try {
const response = await sendRequest(config);
console.log('API Response:', response);
} catch (error) {
console.error('API Request failed:', error.message);
}
You can pass the custom component to show during offline using the render
prop of the OfflineSyncProvider
.
import { OfflineSyncProvider } from './offline-sync-provider';
const App = () => {
// Your application components and logic
};
const rootElement = document.getElementById('root');
ReactDOM.render(
<OfflineSyncProvider
render={({ isOffline, isOnline }) => {
return isOnline ? null : <div>I am offline</div>;
}}
>
<App />
</OfflineSyncProvider>,
rootElement
);
You can track online status change using the onStatusChange
prop of the OfflineSyncProvider
.
import { OfflineSyncProvider } from './offline-sync-provider';
const App = () => {
// Your application components and logic
};
const rootElement = document.getElementById('root');
ReactDOM.render(
<OfflineSyncProvider
onStatusChange={(status)=>{
console.log({status})
}}
>
<App />
</OfflineSyncProvider>,
rootElement
);
You can customize toast notifications using the toastConfig
prop of the OfflineSyncProvider
component. Refer to the react-toastify
documentation for available options.
import { OfflineSyncProvider } from './offline-sync-provider';
const App = () => {
// Your application components and logic
};
const toastConfig = {
position: 'bottom-left',
autoClose: 3000,
};
const rootElement = document.getElementById('root');
ReactDOM.render(
<OfflineSyncProvider toastConfig={toastConfig}>
<App />
</OfflineSyncProvider>,
rootElement
);
This project is licensed under the MIT License.
If you encounter any issues or have suggestions for improvement, please submit an issue. Contributions are welcome! Please fork the repository and create a pull request.
Thank you for using the Offline Sync Provider module! We hope it simplifies handling API requests and enhances the offline experience for your web application. If you have any questions or need further assistance, feel free to reach out to us. Happy coding!
FAQs
**Offline Sync Provider - README**
We found that offline-sync-handler-test 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
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.