Centralize Matrix SDK imports behind a local compatibility module, migrate matrix subpath imports to the boundary, and switch to the $types alias. Upgrade TypeScript to latest so matrix-js-sdk typings resolve correctly before the next cleanup phase.
20 lines
678 B
TypeScript
20 lines
678 B
TypeScript
import { ReactNode, useCallback, useEffect } from 'react';
|
|
import { Capabilities } from '$types/matrix-sdk';
|
|
import { AsyncStatus, useAsyncCallback } from '../hooks/useAsyncCallback';
|
|
import { useMatrixClient } from '../hooks/useMatrixClient';
|
|
|
|
type CapabilitiesLoaderProps = {
|
|
children: (capabilities: Capabilities | undefined) => ReactNode;
|
|
};
|
|
export function CapabilitiesLoader({ children }: CapabilitiesLoaderProps) {
|
|
const mx = useMatrixClient();
|
|
|
|
const [state, load] = useAsyncCallback(useCallback(() => mx.getCapabilities(), [mx]));
|
|
|
|
useEffect(() => {
|
|
load();
|
|
}, [load]);
|
|
|
|
return children(state.status === AsyncStatus.Success ? state.data : undefined);
|
|
}
|