freshyo/packages/ui/hooks/useFocusCallback.ts
2026-01-24 00:13:15 +05:30

16 lines
No EOL
420 B
TypeScript

import { useFocusEffect } from '@react-navigation/native';
import { useCallback } from 'react';
/**
* Hook that calls a callback function when the current screen comes into focus
* @param callback - Function to call when screen gains focus
*/
const useFocusCallback = (callback: () => void) => {
useFocusEffect(
useCallback(() => {
callback();
}, [callback])
);
};
export default useFocusCallback;