AFFiNE/packages/frontend/core/src/hooks/use-data-source-status.ts
EYHN 4b217e6b89
refactor(core): move hooks to core (#5458)
* move @toeverything/hooks -> @affine/core/hooks
* delete @toeverything/hooks

hooks are all business-related logic and are deeply coupled with other parts.

Move them into the core and then reconstruct them by feature.
2024-01-02 08:05:46 +00:00

16 lines
387 B
TypeScript

import { useCallback, useSyncExternalStore } from 'react';
import type { DataSourceAdapter, Status } from 'y-provider';
type UIStatus =
| Status
| {
type: 'unknown';
};
export function useDataSourceStatus(provider: DataSourceAdapter): UIStatus {
return useSyncExternalStore(
provider.subscribeStatusChange,
useCallback(() => provider.status, [provider])
);
}