From f9077d09976f817f3a667f6ec2e573ea84b5a442 Mon Sep 17 00:00:00 2001 From: Hossein Mohammadi Date: Wed, 5 Aug 2020 10:35:57 +0430 Subject: [PATCH 1/3] fix: resolve deps of useBackHandler --- src/useBackHandler.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/useBackHandler.ts b/src/useBackHandler.ts index 470150db..0928291f 100644 --- a/src/useBackHandler.ts +++ b/src/useBackHandler.ts @@ -1,10 +1,11 @@ import {useEffect} from 'react' import {BackHandler} from 'react-native' -export function useBackHandler(handler: () => boolean) { +export function useBackHandler(handler: () => boolean, deps: any[]) { useEffect(() => { BackHandler.addEventListener('hardwareBackPress', handler) return () => BackHandler.removeEventListener('hardwareBackPress', handler) - }, [handler]) + // eslint-disable-next-line react-hooks/exhaustive-deps + }, deps) } From 2d0647dadb0c8fbb2d6243960de4ce19e8e04263 Mon Sep 17 00:00:00 2001 From: Hossein Mohammadi Date: Wed, 5 Aug 2020 10:40:03 +0430 Subject: [PATCH 2/3] docs: readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1b2ea981..f76b0a7d 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ useBackHandler(() => { } // let the default thing happen return false -}) +},[shouldBeHandledHere]) ``` ### `useCameraRoll` From 322a72dccf689e6df4ef23f538b26a2721db22cd Mon Sep 17 00:00:00 2001 From: Hossein Mohammadi Date: Wed, 5 Aug 2020 10:42:43 +0430 Subject: [PATCH 3/3] types: improve type defination --- src/useBackHandler.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/useBackHandler.ts b/src/useBackHandler.ts index 0928291f..b39a4c20 100644 --- a/src/useBackHandler.ts +++ b/src/useBackHandler.ts @@ -1,7 +1,7 @@ -import {useEffect} from 'react' +import {useEffect, DependencyList} from 'react' import {BackHandler} from 'react-native' -export function useBackHandler(handler: () => boolean, deps: any[]) { +export function useBackHandler(handler: () => boolean, deps?: DependencyList) { useEffect(() => { BackHandler.addEventListener('hardwareBackPress', handler)