diff --git a/src/components/views/spaces/SpaceSettingsGeneralTab.tsx b/src/components/views/spaces/SpaceSettingsGeneralTab.tsx index c6549f4ba27..d0def77d11c 100644 --- a/src/components/views/spaces/SpaceSettingsGeneralTab.tsx +++ b/src/components/views/spaces/SpaceSettingsGeneralTab.tsx @@ -48,7 +48,7 @@ const SpaceSettingsGeneralTab = ({ matrixClient: cli, space, onFinished }: IProp const canSetName = space.currentState.maySendStateEvent(EventType.RoomName, userId); const nameChanged = name !== space.name; - const currentTopic = getTopic(space).text; + const currentTopic = getTopic(space)?.text; const [topic, setTopic] = useState(currentTopic); const canSetTopic = space.currentState.maySendStateEvent(EventType.RoomTopic, userId); const topicChanged = topic !== currentTopic; diff --git a/src/hooks/room/useTopic.ts b/src/hooks/room/useTopic.ts index 3f276a4e645..0236b1e88d4 100644 --- a/src/hooks/room/useTopic.ts +++ b/src/hooks/room/useTopic.ts @@ -21,10 +21,11 @@ import { Room } from "matrix-js-sdk/src/models/room"; import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state"; import { parseTopicContent, TopicState } from "matrix-js-sdk/src/content-helpers"; import { MRoomTopicEventContent } from "matrix-js-sdk/src/@types/topic"; +import { Optional } from "matrix-events-sdk"; import { useTypedEventEmitter } from "../useEventEmitter"; -export const getTopic = (room: Room) => { +export const getTopic = (room: Room): Optional => { const content: MRoomTopicEventContent = room?.currentState?.getStateEvents(EventType.RoomTopic, "")?.getContent(); return !!content ? parseTopicContent(content) : null; };