UNPKG

react-native-ui-lib

Version:

<p align="center"> <img src="https://user-images.githubusercontent.com/1780255/105469025-56759000-5ca0-11eb-993d-3568c1fd54f4.png" height="250px" style="display:block"/> </p> <p align="center">UI Toolset & Components Library for React Native</p> <p a

24 lines (22 loc) 790 B
import React, { useEffect, useCallback, useState } from 'react'; import { Constants } from "../../commons/new"; import useDidUpdate from "../useDidUpdate"; const useOrientation = ({ onOrientationChange } = {}) => { const [orientation, setOrientation] = useState(Constants.orientation); const orientationChangeListener = useCallback(() => { setOrientation(Constants.orientation); }, []); useEffect(() => { const listener = Constants.addDimensionsEventListener(orientationChangeListener); return () => Constants.removeDimensionsEventListener(listener); }, []); useDidUpdate(() => { onOrientationChange?.(orientation); // eslint-disable-next-line react-hooks/exhaustive-deps }, [orientation]); return { orientation }; }; export default useOrientation;