mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 13:25:12 +00:00
feat: support get datasource status (#3645)
This commit is contained in:
15
packages/hooks/src/use-data-source-status.ts
Normal file
15
packages/hooks/src/use-data-source-status.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import type { Status, StatusAdapter } from '@affine/y-provider';
|
||||
import { useCallback, useSyncExternalStore } from 'react';
|
||||
|
||||
type UIStatus =
|
||||
| Status
|
||||
| {
|
||||
type: 'unknown';
|
||||
};
|
||||
|
||||
export function useDataSourceStatus(datasource: StatusAdapter): UIStatus {
|
||||
return useSyncExternalStore(
|
||||
datasource.subscribeStatusChange,
|
||||
useCallback(() => datasource.status, [datasource])
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user