Skip to content

Commit

Permalink
refactor: use callback inside useFocusEffect to reduce rerender
Browse files Browse the repository at this point in the history
  • Loading branch information
daledah committed Mar 8, 2025
1 parent 2c5e44d commit 227fb28
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions src/hooks/useHandleBackButton/index.android.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import {useFocusEffect} from '@react-navigation/native';
import {useCallback} from 'react';
import {BackHandler} from 'react-native';
import type UseHandleBackButtonCallback from './type';

export default function useHandleBackButton(callback: UseHandleBackButtonCallback) {
useFocusEffect(() => {
const backHandler = BackHandler.addEventListener('hardwareBackPress', callback);

return () => backHandler.remove();
});
useFocusEffect(
useCallback(() => {
const backHandler = BackHandler.addEventListener('hardwareBackPress', callback);
return () => backHandler.remove();
}, [callback]),
);
}
2 changes: 1 addition & 1 deletion src/pages/Search/SearchPageNarrow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {useSearchContext} from '@components/Search/SearchContext';
import SearchPageHeader from '@components/Search/SearchPageHeader/SearchPageHeader';
import SearchStatusBar from '@components/Search/SearchPageHeader/SearchStatusBar';
import type {SearchQueryJSON} from '@components/Search/types';
import useHandleBackButton from '@hooks//useHandleBackButton';
import useHandleBackButton from '@hooks/useHandleBackButton';
import useLocalize from '@hooks/useLocalize';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useStyleUtils from '@hooks/useStyleUtils';
Expand Down

0 comments on commit 227fb28

Please sign in to comment.