From 4fdada55a32ba9463196b50f73b955c4b0da685b Mon Sep 17 00:00:00 2001
From: Alberto <alberto@expensify.com>
Date: Mon, 5 Jun 2023 10:55:13 +0200
Subject: [PATCH 1/5] Add null check before react effect

---
 src/components/LHNOptionsList/OptionRowLHN.js | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/components/LHNOptionsList/OptionRowLHN.js b/src/components/LHNOptionsList/OptionRowLHN.js
index ffc0584b6fff..099764869283 100644
--- a/src/components/LHNOptionsList/OptionRowLHN.js
+++ b/src/components/LHNOptionsList/OptionRowLHN.js
@@ -56,14 +56,14 @@ const defaultProps = {
 const OptionRowLHN = (props) => {
     const optionItem = SidebarUtils.getOptionData(props.reportID);
 
-    React.useEffect(() => {
-        ReportActionContextMenu.hideContextMenu(false);
-    }, [optionItem.isPinned]);
-
     if (!optionItem) {
         return null;
     }
 
+    React.useEffect(() => {
+        ReportActionContextMenu.hideContextMenu(false);
+    }, [optionItem.isPinned]);
+
     let popoverAnchor = null;
     const textStyle = props.isFocused ? styles.sidebarLinkActiveText : styles.sidebarLinkText;
     const textUnreadStyle = optionItem.isUnread ? [textStyle, styles.sidebarLinkTextBold] : [textStyle];

From 8d7338ea4f5f25d5c2f71f3c7873dbfcfae90940 Mon Sep 17 00:00:00 2001
From: Alberto <alberto@expensify.com>
Date: Mon, 5 Jun 2023 11:36:29 +0200
Subject: [PATCH 2/5] have the check inside the hook

---
 src/components/LHNOptionsList/OptionRowLHN.js | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/components/LHNOptionsList/OptionRowLHN.js b/src/components/LHNOptionsList/OptionRowLHN.js
index 099764869283..c466190a9641 100644
--- a/src/components/LHNOptionsList/OptionRowLHN.js
+++ b/src/components/LHNOptionsList/OptionRowLHN.js
@@ -56,14 +56,16 @@ const defaultProps = {
 const OptionRowLHN = (props) => {
     const optionItem = SidebarUtils.getOptionData(props.reportID);
 
+    React.useEffect(() => {
+        if (optionItem) {
+            ReportActionContextMenu.hideContextMenu(false);
+        }
+    }, [optionItem.isPinned]);
+
     if (!optionItem) {
         return null;
     }
 
-    React.useEffect(() => {
-        ReportActionContextMenu.hideContextMenu(false);
-    }, [optionItem.isPinned]);
-
     let popoverAnchor = null;
     const textStyle = props.isFocused ? styles.sidebarLinkActiveText : styles.sidebarLinkText;
     const textUnreadStyle = optionItem.isUnread ? [textStyle, styles.sidebarLinkTextBold] : [textStyle];

From dd7458099ded5d7331002b518359a3bce99d9ac6 Mon Sep 17 00:00:00 2001
From: Alberto <alberto@expensify.com>
Date: Mon, 5 Jun 2023 11:49:40 +0200
Subject: [PATCH 3/5] trigger by optionItem

---
 src/components/LHNOptionsList/OptionRowLHN.js | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/components/LHNOptionsList/OptionRowLHN.js b/src/components/LHNOptionsList/OptionRowLHN.js
index c466190a9641..a89ee04b69f0 100644
--- a/src/components/LHNOptionsList/OptionRowLHN.js
+++ b/src/components/LHNOptionsList/OptionRowLHN.js
@@ -57,10 +57,10 @@ const OptionRowLHN = (props) => {
     const optionItem = SidebarUtils.getOptionData(props.reportID);
 
     React.useEffect(() => {
-        if (optionItem) {
+        if (optionItem && optionItem.isPinned) {
             ReportActionContextMenu.hideContextMenu(false);
         }
-    }, [optionItem.isPinned]);
+    }, [optionItem]);
 
     if (!optionItem) {
         return null;

From 09704cfd2f3400bd4776f7efe4dfd8364cd650b9 Mon Sep 17 00:00:00 2001
From: Alberto <alberto@expensify.com>
Date: Mon, 5 Jun 2023 11:55:10 +0200
Subject: [PATCH 4/5] lint

---
 src/components/LHNOptionsList/OptionRowLHN.js | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/components/LHNOptionsList/OptionRowLHN.js b/src/components/LHNOptionsList/OptionRowLHN.js
index a89ee04b69f0..e9798d467ae8 100644
--- a/src/components/LHNOptionsList/OptionRowLHN.js
+++ b/src/components/LHNOptionsList/OptionRowLHN.js
@@ -57,9 +57,10 @@ const OptionRowLHN = (props) => {
     const optionItem = SidebarUtils.getOptionData(props.reportID);
 
     React.useEffect(() => {
-        if (optionItem && optionItem.isPinned) {
-            ReportActionContextMenu.hideContextMenu(false);
+        if (!optionItem || !optionItem.isPinned) {
+            return;
         }
+        ReportActionContextMenu.hideContextMenu(false);
     }, [optionItem]);
 
     if (!optionItem) {

From b609752d16aa925f602f04049e572fd84cd3dc02 Mon Sep 17 00:00:00 2001
From: Alberto <alberto@expensify.com>
Date: Mon, 5 Jun 2023 12:24:48 +0200
Subject: [PATCH 5/5] correct behavior

---
 src/components/LHNOptionsList/OptionRowLHN.js | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/src/components/LHNOptionsList/OptionRowLHN.js b/src/components/LHNOptionsList/OptionRowLHN.js
index e9798d467ae8..42e9168ba940 100644
--- a/src/components/LHNOptionsList/OptionRowLHN.js
+++ b/src/components/LHNOptionsList/OptionRowLHN.js
@@ -55,13 +55,11 @@ const defaultProps = {
 
 const OptionRowLHN = (props) => {
     const optionItem = SidebarUtils.getOptionData(props.reportID);
+    const isPinned = _.get(optionItem, 'isPinned', false);
 
     React.useEffect(() => {
-        if (!optionItem || !optionItem.isPinned) {
-            return;
-        }
         ReportActionContextMenu.hideContextMenu(false);
-    }, [optionItem]);
+    }, [isPinned]);
 
     if (!optionItem) {
         return null;
