23 lines
540 B
TypeScript
23 lines
540 B
TypeScript
|
|
import { useState, useCallback } from 'react';
|
||
|
|
import { useMatrixClient } from './useMatrixClient';
|
||
|
|
import { useAccountDataCallback } from './useAccountDataCallback';
|
||
|
|
|
||
|
|
export function useAccountData(eventType: string) {
|
||
|
|
const mx = useMatrixClient();
|
||
|
|
const [event, setEvent] = useState(() => mx.getAccountData(eventType));
|
||
|
|
|
||
|
|
useAccountDataCallback(
|
||
|
|
mx,
|
||
|
|
useCallback(
|
||
|
|
(evt) => {
|
||
|
|
if (evt.getType() === eventType) {
|
||
|
|
setEvent(evt);
|
||
|
|
}
|
||
|
|
},
|
||
|
|
[eventType, setEvent]
|
||
|
|
)
|
||
|
|
);
|
||
|
|
|
||
|
|
return event;
|
||
|
|
}
|