freshyo/packages/ui/hooks/useFocusCallback.ts
2026-11-18 16:52:41 +05:30

16 lines
No EOL
407 B
TypeScript

import { useFocusEffect } from 'expo-router';
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;