refactor!: next generation AFFiNE code structure (#1176)

This commit is contained in:
Himself65
2023-03-01 01:40:01 -06:00
committed by GitHub
parent 2dcccc772c
commit e0481d29ad
270 changed files with 8308 additions and 6829 deletions
+21
View File
@@ -0,0 +1,21 @@
import { useCallback, useSyncExternalStore } from 'react';
const getOnLineStatus = () =>
typeof navigator !== 'undefined' && typeof navigator.onLine === 'boolean'
? navigator.onLine
: true;
export function useSystemOnline(): boolean {
return useSyncExternalStore(
useCallback(onStoreChange => {
window.addEventListener('online', onStoreChange);
window.addEventListener('offline', onStoreChange);
return () => {
window.removeEventListener('online', onStoreChange);
window.removeEventListener('offline', onStoreChange);
};
}, []),
useCallback(() => getOnLineStatus(), []),
useCallback(() => true, [])
);
}