Skip to content

Commit c11a328

Browse files
committed
Stabilize Concierge draft Pusher subscription
1 parent 89ed15a commit c11a328

1 file changed

Lines changed: 16 additions & 10 deletions

File tree

src/pages/inbox/ConciergeDraftContext.tsx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {getReportChatType} from '@selectors/Report';
2-
import React, {createContext, useContext, useEffect, useState} from 'react';
2+
import React, {createContext, useCallback, useContext, useEffect, useMemo, useState} from 'react';
33
import useOnyx from '@hooks/useOnyx';
44
import {getReportChannelName} from '@libs/actions/Report';
55
import Log from '@libs/Log';
@@ -56,9 +56,9 @@ function ConciergeDraftProvider({reportID, children}: React.PropsWithChildren<{r
5656
function ConciergeDraftGate({reportID, children}: React.PropsWithChildren<{reportID: string}>) {
5757
const [draft, setDraft] = useState<ConciergeDraft | null>(null);
5858

59-
const clearDraft = () => {
59+
const clearDraft = useCallback(() => {
6060
setDraft(null);
61-
};
61+
}, []);
6262

6363
useEffect(() => {
6464
const channelName = getReportChannelName(reportID);
@@ -98,14 +98,20 @@ function ConciergeDraftGate({reportID, children}: React.PropsWithChildren<{repor
9898
};
9999
}, [clearDraft, reportID]);
100100

101-
const stateValue: ConciergeDraftState = {
102-
draftReportAction: draft?.reportAction ?? null,
103-
hasActiveDraft: !!draft?.reportAction,
104-
};
101+
const stateValue: ConciergeDraftState = useMemo(
102+
() => ({
103+
draftReportAction: draft?.reportAction ?? null,
104+
hasActiveDraft: !!draft?.reportAction,
105+
}),
106+
[draft?.reportAction],
107+
);
105108

106-
const actionsValue: ConciergeDraftActions = {
107-
clearDraft,
108-
};
109+
const actionsValue: ConciergeDraftActions = useMemo(
110+
() => ({
111+
clearDraft,
112+
}),
113+
[clearDraft],
114+
);
109115

110116
return (
111117
<ConciergeDraftActionsContext.Provider value={actionsValue}>

0 commit comments

Comments
 (0)