Skip to content

Commit ab4d5f3

Browse files
committed
optimize the code
1 parent b9ef612 commit ab4d5f3

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/pages/home/report/ReportActionItem.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,17 @@ function ReportActionItem(props) {
138138
const originalReportID = ReportUtils.getOriginalReportID(props.report.reportID, props.action);
139139
const originalReport = props.report.reportID === originalReportID ? props.report : ReportUtils.getReport(originalReportID);
140140

141-
useEffect(() => {
142-
const isAttachment = ReportUtils.isReportMessageAttachment(_.last(props.action.message));
143-
if (!isAttachment) {
144-
return;
145-
}
146-
updateHiddenAttachments(props.action.reportActionID, isHidden);
147-
}, [props.action.reportActionID, props.action.message, isHidden, updateHiddenAttachments]);
141+
const updateHiddenState = useCallback(
142+
(isHiddenValue) => {
143+
setIsHidden(isHiddenValue);
144+
const isAttachment = ReportUtils.isReportMessageAttachment(_.last(props.action.message));
145+
if (!isAttachment) {
146+
return;
147+
}
148+
updateHiddenAttachments(props.action.reportActionID, isHiddenValue);
149+
},
150+
[props.action.reportActionID, props.action.message, updateHiddenAttachments],
151+
);
148152

149153
useEffect(
150154
() => () => {
@@ -371,7 +375,7 @@ function ReportActionItem(props) {
371375
<Button
372376
small
373377
style={[styles.mt2, styles.alignSelfStart]}
374-
onPress={() => setIsHidden(!isHidden)}
378+
onPress={() => updateHiddenState(!isHidden)}
375379
>
376380
<Text
377381
style={styles.buttonSmallText}

0 commit comments

Comments
 (0)