20 lines
693 B
TypeScript
20 lines
693 B
TypeScript
import { ReactNode, useCallback, useEffect } from 'react';
|
|
import { AsyncStatus, useAsyncCallback } from '../hooks/useAsyncCallback';
|
|
import { useMatrixClient } from '../hooks/useMatrixClient';
|
|
import { MediaConfig } from '../hooks/useMediaConfig';
|
|
|
|
type MediaConfigLoaderProps = {
|
|
children: (mediaConfig: MediaConfig | undefined) => ReactNode;
|
|
};
|
|
export function MediaConfigLoader({ children }: MediaConfigLoaderProps) {
|
|
const mx = useMatrixClient();
|
|
|
|
const [state, load] = useAsyncCallback(useCallback(() => mx.getMediaConfig(), [mx]));
|
|
|
|
useEffect(() => {
|
|
load().catch(() => {});
|
|
}, [load]);
|
|
|
|
return children(state.status === AsyncStatus.Success ? state.data : undefined);
|
|
}
|