react-native-rnevents
Version:
The package was created for React Native. It allows to open webpages, make a phone call, call using Viber, Whatsapp and Telegram, take a keyboard event for hooks and make hooks components to work.
24 lines (20 loc) • 822 B
JavaScript
/************************************************************************
* Copyright (c) Amur
* https://github.com/AmurKhoyetsyan/react-native-rnevents.git
*
* React native BackHandler for hooks
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*************************************************************************/
import React, { useEffect } from "react";
import { BackHandler } from "react-native";
export const BackHandlerEvent = (callback) => {
useEffect(() => {
BackHandler.addEventListener("hardwareBackPress", callback);
return () => {
BackHandler.removeEventListener("hardwareBackPress", callback);
};
}, [callback]);
};
export default BackHandlerEvent;