UNPKG

@resourge/react-fetch

Version:

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

36 lines (33 loc) 908 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 { useRef, useEffect } from 'react'; import { IS_DEV } from '../../utils/constants'; const useOnScroll = scrollMethod => { const ref = useRef(null); const onScrollRef = useRef(scrollMethod); onScrollRef.current = scrollMethod; if (IS_DEV) { useEffect(() => { if (!ref.current) { throw new Error('On react-native \'ref\' needs to be set, as react-native doesn\'t have window'); } }, []); } const onScroll = event => { onScrollRef.current({ left: event.nativeEvent.contentOffset.x, top: event.nativeEvent.contentOffset.y }); }; return [ref, onScroll]; }; export { useOnScroll }; //# sourceMappingURL=useOnScroll.native.js.map