From 212977c4ac42aef164b0e7e1ca4c7fae3439eee3 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Fri, 31 Mar 2023 10:35:02 +0100 Subject: [PATCH] Apply `strictNullChecks` to `src/contexts/*` (#10490) --- .../views/rooms/wysiwyg_composer/hooks/useEditing.ts | 3 ++- .../views/rooms/wysiwyg_composer/hooks/useInitialContent.ts | 2 +- src/contexts/MatrixClientContext.tsx | 4 ++-- src/contexts/SDKContext.ts | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/components/views/rooms/wysiwyg_composer/hooks/useEditing.ts b/src/components/views/rooms/wysiwyg_composer/hooks/useEditing.ts index c5648e7e65..862b749502 100644 --- a/src/components/views/rooms/wysiwyg_composer/hooks/useEditing.ts +++ b/src/components/views/rooms/wysiwyg_composer/hooks/useEditing.ts @@ -46,7 +46,8 @@ export function useEditing( ); const editMessageMemoized = useCallback( - () => content !== undefined && editMessage(content, { roomContext, mxClient, editorStateTransfer }), + () => + !!mxClient && content !== undefined && editMessage(content, { roomContext, mxClient, editorStateTransfer }), [content, roomContext, mxClient, editorStateTransfer], ); diff --git a/src/components/views/rooms/wysiwyg_composer/hooks/useInitialContent.ts b/src/components/views/rooms/wysiwyg_composer/hooks/useInitialContent.ts index f4612a097e..1bed0f0c74 100644 --- a/src/components/views/rooms/wysiwyg_composer/hooks/useInitialContent.ts +++ b/src/components/views/rooms/wysiwyg_composer/hooks/useInitialContent.ts @@ -69,7 +69,7 @@ export function useInitialContent(editorStateTransfer: EditorStateTransfer): str const mxClient = useMatrixClientContext(); return useMemo(() => { - if (editorStateTransfer && roomContext.room) { + if (editorStateTransfer && roomContext.room && mxClient) { return parseEditorStateTransfer(editorStateTransfer, roomContext.room, mxClient); } }, [editorStateTransfer, roomContext, mxClient]); diff --git a/src/contexts/MatrixClientContext.tsx b/src/contexts/MatrixClientContext.tsx index e5d7ca304c..4c02f066b6 100644 --- a/src/contexts/MatrixClientContext.tsx +++ b/src/contexts/MatrixClientContext.tsx @@ -25,7 +25,7 @@ import React, { } from "react"; import { MatrixClient } from "matrix-js-sdk/src/client"; -const MatrixClientContext = createContext(undefined); +const MatrixClientContext = createContext(undefined); MatrixClientContext.displayName = "MatrixClientContext"; export default MatrixClientContext; @@ -33,7 +33,7 @@ export interface MatrixClientProps { mxClient: MatrixClient; } -export function useMatrixClientContext(): MatrixClient { +export function useMatrixClientContext(): MatrixClient | undefined { return useContext(MatrixClientContext); } diff --git a/src/contexts/SDKContext.ts b/src/contexts/SDKContext.ts index 79a509f20b..82b47d09c4 100644 --- a/src/contexts/SDKContext.ts +++ b/src/contexts/SDKContext.ts @@ -38,7 +38,7 @@ import { VoiceBroadcastRecordingsStore, } from "../voice-broadcast"; -export const SDKContext = createContext(undefined); +export const SDKContext = createContext(undefined); SDKContext.displayName = "SDKContext"; /**