@adembacaj/react-native-hooks
v1.0.1
Published
Custom hooks that can help during development
Downloads
3
Readme
@adembacaj/react-native-hooks
Custom hooks that can help during development
Installation
npm install @adembacaj/react-native-hooks
or if you are using Expo
npx expo install @adembacaj/react-native-hooks
Usage
useAppActive
import { useAppActive } from '@adembacaj/react-native-hooks';
const isAppActive = useAppActive();
useDimensions
import { useDimensions } from '@adembacaj/react-native-hooks';
const { windowWidth, windowHeight, screenWidth, screenHeight } =
useDimensions();
useIsMounted
import { useIsMounted } from '@adembacaj/react-native-hooks';
const isMounted = useIsMounted();
useKeyboard
import { useKeyboard } from '@adembacaj/react-native-hooks';
const { isKeyboardOpen } = useKeyboard();
useOrientation
import { useOrientation } from '@adembacaj/react-native-hooks';
const orientation = useOrientation();
if (orientation === 'PORTRAIT') {
//do something
} else if (orientation === 'LANDSCAPE') {
//do something
}
useForceUpdate
import { useForceUpdate } from '@adembacaj/react-native-hooks';
const { showForceUpdate, setOptions } = useForceUpdate();
const checkForceUpdate = () => {
setOptions({
minRequiredVersion: '1.9.0',
currentVersion: '1.7.6', // you can use react-native-device-info to get app version installed
});
};
useEffect(() => {
if (showForceUpdate) {
Alert.alert('Update!', 'There is a new update');
}
}, [showForceUpdate]);
useTimeout
import { useTimeout } from '@adembacaj/react-native-hooks';
const { clear, reset } = useTimeout(() => setCount(0), 1000);
useDebounce
import { useDebounce } from '@adembacaj/react-native-hooks';
useDebounce(() => alert(count), 1000, [count]);
useArray
import { useArray } from '@adembacaj/react-native-hooks';
const { array, set, push, remove, filter, update, clear } = useArray([
1, 2, 3, 4, 5, 6,
]);
useAsyncEffect
import { useAsyncEffect } from '@adembacaj/react-native-hooks';
useAsyncEffect(async () => {
const data = await fetchData();
// Do something with the data
return () => {
// Cleanup (if needed)
};
}, [someDependency]);
useModal
import { useModal } from '@adembacaj/react-native-hooks';
const { isVisible, showModal, hideModal } = useModal();
Contributing
See the contributing guide to learn how to contribute to the repository and the development workflow.
License
MIT
Made with create-react-native-library