best practices cleanup chats code review

This commit is contained in:
Dean 2024-02-20 13:06:01 -08:00
parent 61f9add741
commit b802bb01e6

View File

@ -1,9 +1,10 @@
import React, { createContext, useContext, useEffect, useState } from "react"; import React, { createContext, useContext, useEffect, useState } from "react";
import { Dimensions } from "react-native"; import { Dimensions } from "react-native";
const OrientationContext = createContext(); const OrientationContext = createContext<string | null>(null);
export const useOrientation = () => useContext(OrientationContext); export const useOrientation = (): string | null =>
useContext(OrientationContext);
export const OrientationProvider = ({ children }) => { export const OrientationProvider = ({ children }) => {
const [orientation, setOrientation] = useState(getOrientation()); const [orientation, setOrientation] = useState(getOrientation());
@ -18,10 +19,8 @@ export const OrientationProvider = ({ children }) => {
setOrientation(getOrientation()); setOrientation(getOrientation());
}; };
const subscription = Dimensions.addEventListener( const subscription = Dimensions.addChangeListener(updateOrientation);
"change",
updateOrientation,
);
return () => subscription.remove(); return () => subscription.remove();
}, []); }, []);