|
1 | 1 | 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'; |
3 | 3 | import useOnyx from '@hooks/useOnyx'; |
4 | 4 | import {getReportChannelName} from '@libs/actions/Report'; |
5 | 5 | import Log from '@libs/Log'; |
@@ -56,9 +56,9 @@ function ConciergeDraftProvider({reportID, children}: React.PropsWithChildren<{r |
56 | 56 | function ConciergeDraftGate({reportID, children}: React.PropsWithChildren<{reportID: string}>) { |
57 | 57 | const [draft, setDraft] = useState<ConciergeDraft | null>(null); |
58 | 58 |
|
59 | | - const clearDraft = () => { |
| 59 | + const clearDraft = useCallback(() => { |
60 | 60 | setDraft(null); |
61 | | - }; |
| 61 | + }, []); |
62 | 62 |
|
63 | 63 | useEffect(() => { |
64 | 64 | const channelName = getReportChannelName(reportID); |
@@ -98,14 +98,20 @@ function ConciergeDraftGate({reportID, children}: React.PropsWithChildren<{repor |
98 | 98 | }; |
99 | 99 | }, [clearDraft, reportID]); |
100 | 100 |
|
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 | + ); |
105 | 108 |
|
106 | | - const actionsValue: ConciergeDraftActions = { |
107 | | - clearDraft, |
108 | | - }; |
| 109 | + const actionsValue: ConciergeDraftActions = useMemo( |
| 110 | + () => ({ |
| 111 | + clearDraft, |
| 112 | + }), |
| 113 | + [clearDraft], |
| 114 | + ); |
109 | 115 |
|
110 | 116 | return ( |
111 | 117 | <ConciergeDraftActionsContext.Provider value={actionsValue}> |
|
0 commit comments