import { MatrixClient } from 'matrix-js-sdk';
import { useEffect } from 'react';
import { subscribeStateEvents } from '../state/stateEventDemux';
import type { StateEventCallback } from './stateEventCallback.types';

export type { StateEventCallback } from './stateEventCallback.types';

export const useStateEventCallback = (mx: MatrixClient, onStateEvent: StateEventCallback) => {
  useEffect(() => subscribeStateEvents(mx, onStateEvent), [mx, onStateEvent]);
};
