-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
index.android.tsx
31 lines (26 loc) · 1.31 KB
/
index.android.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import {useEffect} from 'react';
import {withOnyx} from 'react-native-onyx';
import ONYXKEYS from '@src/ONYXKEYS';
import type {SilentCommentUpdaterOnyxProps, SilentCommentUpdaterProps} from './types';
/**
* Adding .android component to disable updating comment when prev comment is different
* it fixes issue on Android, assuming we don't need tab sync on mobiles - https://github.com/Expensify/App/issues/28562
*/
/**
* This component doesn't render anything. It runs a side effect to update the comment of a report under certain conditions.
* It is connected to the actual draft comment in onyx. The comment in onyx might updates multiple times, and we want to avoid
* re-rendering a UI component for that. That's why the side effect was moved down to a separate component.
*/
function SilentCommentUpdater({comment, updateComment}: SilentCommentUpdaterProps) {
useEffect(() => {
updateComment(comment ?? '');
// eslint-disable-next-line react-hooks/exhaustive-deps -- We need to run this on mount
}, []);
return null;
}
SilentCommentUpdater.displayName = 'SilentCommentUpdater';
export default withOnyx<SilentCommentUpdaterProps, SilentCommentUpdaterOnyxProps>({
comment: {
key: ({reportID}) => `${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${reportID}`,
},
})(SilentCommentUpdater);