1
+ import { useIsFocused } from '@react-navigation/native' ;
1
2
import React , { useEffect , useMemo , useState } from 'react' ;
2
3
import { View } from 'react-native' ;
3
4
import { useOnyx } from 'react-native-onyx' ;
@@ -45,7 +46,7 @@ function CategorySettingsPage({
45
46
} ,
46
47
navigation,
47
48
} : CategorySettingsPageProps ) {
48
- const [ policyCategories ] = useOnyx ( `${ ONYXKEYS . COLLECTION . POLICY_CATEGORIES } ${ policyID } ` ) ;
49
+ const [ policyCategories ] = useOnyx ( `${ ONYXKEYS . COLLECTION . POLICY_CATEGORIES } ${ policyID } ` , { canBeMissing : false } ) ;
49
50
const styles = useThemeStyles ( ) ;
50
51
const { translate} = useLocalize ( ) ;
51
52
const [ deleteCategoryConfirmModalVisible , setDeleteCategoryConfirmModalVisible ] = useState ( false ) ;
@@ -62,12 +63,14 @@ function CategorySettingsPage({
62
63
Navigation . goBack ( isQuickSettingsFlow ? ROUTES . SETTINGS_CATEGORIES_ROOT . getRoute ( policyID , backTo ) : undefined ) ;
63
64
} ;
64
65
66
+ const isFocused = useIsFocused ( ) ;
67
+
65
68
useEffect ( ( ) => {
66
- if ( policyCategory ?. name === categoryName || ! policyCategory ) {
69
+ if ( policyCategory ?. name === categoryName || ! isFocused ) {
67
70
return ;
68
71
}
69
72
navigation . setParams ( { categoryName : policyCategory ?. name } ) ;
70
- } , [ categoryName , navigation , policyCategory ] ) ;
73
+ } , [ categoryName , navigation , policyCategory ?. name , isFocused ] ) ;
71
74
72
75
const flagAmountsOverText = useMemo ( ( ) => {
73
76
if ( policyCategory ?. maxExpenseAmount === CONST . DISABLED_MAX_EXPENSE_VALUE || ! policyCategory ?. maxExpenseAmount ) {
0 commit comments