UNPKG

@resourge/react-fetch

Version:

[![License](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)

42 lines (39 loc) 930 B
/** * react-fetch v1.41.3 * * Copyright (c) resourge. * * This source code is licensed under the MIT license found in the * LICENSE.md file in the root directory of this source tree. * * @license MIT */ import { useEffect } from 'react'; import { AppState, Platform } from 'react-native'; const useOnFocus = (cb, onWindowFocus) => { useEffect(() => { if (onWindowFocus) { const { focus, blur, clear } = cb(); const onAppStateChange = status => { if (Platform.OS !== 'web') { if (status === 'active') { focus(); return; } blur(); } }; const subscription = AppState.addEventListener('change', onAppStateChange); return () => { clear(); subscription.remove(); }; } }, [onWindowFocus]); }; export { useOnFocus }; //# sourceMappingURL=useOnFocus.native.js.map