diff --git a/src/context/OrientationContext.tsx b/src/context/OrientationContext.tsx index 551e99a..2e040e9 100644 --- a/src/context/OrientationContext.tsx +++ b/src/context/OrientationContext.tsx @@ -1,9 +1,10 @@ import React, { createContext, useContext, useEffect, useState } from "react"; import { Dimensions } from "react-native"; -const OrientationContext = createContext(); +const OrientationContext = createContext(null); -export const useOrientation = () => useContext(OrientationContext); +export const useOrientation = (): string | null => + useContext(OrientationContext); export const OrientationProvider = ({ children }) => { const [orientation, setOrientation] = useState(getOrientation()); @@ -18,10 +19,8 @@ export const OrientationProvider = ({ children }) => { setOrientation(getOrientation()); }; - const subscription = Dimensions.addEventListener( - "change", - updateOrientation, - ); + const subscription = Dimensions.addChangeListener(updateOrientation); + return () => subscription.remove(); }, []);