Conform more of the codebase to strictNullChecks (#10573)

* Conform more of the codebase to `strictNullChecks`

* Iterate
This commit is contained in:
Michael Telatynski 2023-04-13 08:52:57 +01:00 committed by GitHub
parent b4d7f6b592
commit 605ef084ec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
34 changed files with 119 additions and 104 deletions

View file

@ -28,8 +28,8 @@ const defaultMapper: Mapper<RoomState> = (roomState: RoomState) => roomState;
export const useRoomState = <T extends any = RoomState>(
room?: Room,
mapper: Mapper<T> = defaultMapper as Mapper<T>,
): T | undefined => {
const [value, setValue] = useState<T | undefined>(room ? mapper(room.currentState) : undefined);
): T => {
const [value, setValue] = useState<T>(room ? mapper(room.currentState) : (undefined as T));
const update = useCallback(() => {
if (!room) return;
@ -40,8 +40,8 @@ export const useRoomState = <T extends any = RoomState>(
useEffect(() => {
update();
return () => {
setValue(undefined);
setValue(room ? mapper(room.currentState) : (undefined as T));
};
}, [update]);
}, [room, mapper, update]);
return value;
};