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.
18 lines
532 B
TypeScript
18 lines
532 B
TypeScript
import { MatrixClient, MatrixEvent, RoomState, RoomStateEvent } from '$types/matrix-sdk';
|
|
import { useEffect } from 'react';
|
|
|
|
export type StateEventCallback = (
|
|
event: MatrixEvent,
|
|
state: RoomState,
|
|
lastStateEvent: MatrixEvent | null
|
|
) => void;
|
|
|
|
export const useStateEventCallback = (mx: MatrixClient, onStateEvent: StateEventCallback) => {
|
|
useEffect(() => {
|
|
mx.on(RoomStateEvent.Events, onStateEvent);
|
|
return () => {
|
|
mx.removeListener(RoomStateEvent.Events, onStateEvent);
|
|
};
|
|
}, [mx, onStateEvent]);
|
|
};
|