Skip to content

Commit

Permalink
fix(use-is-online): improve types
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Jan 10, 2025
1 parent 6e4dd5d commit af38e91
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/use-is-online/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@

import { useSyncExternalStore } from 'react';

const subscribe: Parameters<typeof useSyncExternalStore>[0] = (callback) => {
window.addEventListener('online', callback);
window.addEventListener('offline', callback);
function subscribe(onStoreChange: () => void): () => void {
window.addEventListener('online', onStoreChange);
window.addEventListener('offline', onStoreChange);
return () => {
window.removeEventListener('online', callback);
window.removeEventListener('offline', callback);
window.removeEventListener('online', onStoreChange);
window.removeEventListener('offline', onStoreChange);
};
};
}

const getSnapshot: Parameters<typeof useSyncExternalStore<boolean>>[1] = () => {
function getSnapshot() {
if (typeof window === 'undefined') {
return false;
}

return navigator.onLine;
};
}

/** @see https://foxact.skk.moe/use-is-online */
export function useIsOnline() {
Expand Down

0 comments on commit af38e91

Please sign in to comment.