Use mapped types around account data events (#28752)
* Use mapped types around account data events --------- Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
@@ -7,14 +7,14 @@ Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
import { useCallback, useState } from "react";
|
||||
import { ClientEvent, MatrixClient, MatrixEvent } from "matrix-js-sdk/src/matrix";
|
||||
import { AccountDataEvents, ClientEvent, MatrixClient, MatrixEvent } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import { useTypedEventEmitter } from "./useEventEmitter";
|
||||
|
||||
const tryGetContent = <T extends {}>(ev?: MatrixEvent): T | undefined => ev?.getContent<T>();
|
||||
|
||||
// Hook to simplify listening to Matrix account data
|
||||
export const useAccountData = <T extends {}>(cli: MatrixClient, eventType: string): T => {
|
||||
export const useAccountData = <T extends {}>(cli: MatrixClient, eventType: keyof AccountDataEvents): T => {
|
||||
const [value, setValue] = useState<T | undefined>(() => tryGetContent<T>(cli.getAccountData(eventType)));
|
||||
|
||||
const handler = useCallback(
|
||||
|
||||
Reference in New Issue
Block a user