From f59baf1efb1c40a95724ad20b858baae2a46d528 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 14 Sep 2021 14:41:55 +0100 Subject: [PATCH] Tidy some types --- src/hooks/useEventEmitter.ts | 12 ++++++++++-- src/hooks/useRoomState.ts | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/hooks/useEventEmitter.ts b/src/hooks/useEventEmitter.ts index 74b23f0198..693eebc0e3 100644 --- a/src/hooks/useEventEmitter.ts +++ b/src/hooks/useEventEmitter.ts @@ -20,7 +20,11 @@ import type { EventEmitter } from "events"; type Handler = (...args: any[]) => void; // Hook to wrap event emitter on and removeListener in hook lifecycle -export const useEventEmitter = (emitter: EventEmitter, eventName: string | symbol, handler: Handler) => { +export const useEventEmitter = ( + emitter: EventEmitter | undefined, + eventName: string | symbol, + handler: Handler, +) => { // Create a ref that stores handler const savedHandler = useRef(handler); @@ -51,7 +55,11 @@ export const useEventEmitter = (emitter: EventEmitter, eventName: string | symbo type Mapper = (...args: any[]) => T; -export const useEventEmitterState = (emitter: EventEmitter, eventName: string | symbol, fn: Mapper): T => { +export const useEventEmitterState = ( + emitter: EventEmitter | undefined, + eventName: string | symbol, + fn: Mapper, +): T => { const [value, setValue] = useState(fn()); const handler = useCallback((...args: any[]) => { setValue(fn(...args)); diff --git a/src/hooks/useRoomState.ts b/src/hooks/useRoomState.ts index e778acf8a9..89c94df10b 100644 --- a/src/hooks/useRoomState.ts +++ b/src/hooks/useRoomState.ts @@ -25,7 +25,7 @@ const defaultMapper: Mapper = (roomState: RoomState) => roomState; // Hook to simplify watching Matrix Room state export const useRoomState = ( - room: Room, + room?: Room, mapper: Mapper = defaultMapper as Mapper, ): T => { const [value, setValue] = useState(room ? mapper(room.currentState) : undefined);