mirror of
https://github.com/SableClient/Sable.git
synced 2026-12-06 08:42:23 -08:00
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.
29 lines
851 B
TypeScript
29 lines
851 B
TypeScript
import { useCallback, useMemo } from 'react';
|
|
import { Room } from '$types/matrix-sdk';
|
|
import { StateEvent } from '../../types/matrix/room';
|
|
import { useForceUpdate } from './useForceUpdate';
|
|
import { useStateEventCallback } from './useStateEventCallback';
|
|
import { getStateEvents } from '../utils/room';
|
|
|
|
export const useStateEvents = (room: Room, eventType: StateEvent) => {
|
|
const [updateCount, forceUpdate] = useForceUpdate();
|
|
|
|
useStateEventCallback(
|
|
room.client,
|
|
useCallback(
|
|
(event) => {
|
|
if (event.getRoomId() === room.roomId && event.getType() === eventType) {
|
|
forceUpdate();
|
|
}
|
|
},
|
|
[room, eventType, forceUpdate]
|
|
)
|
|
);
|
|
|
|
return useMemo(
|
|
() => getStateEvents(room, eventType),
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
[room, eventType, updateCount]
|
|
);
|
|
};
|