forked from cemaden-educacao/WPD-MobileApp
GabrielTrettel
4 years ago
3 changed files with 76 additions and 13 deletions
@ -0,0 +1,25 @@ |
|||
import { useEffect, useState } from "react"; |
|||
import { useIsFocused } from "@react-navigation/native"; |
|||
|
|||
/* |
|||
|
|||
NOTE: This hook is used this way because react-navigation/native |
|||
IsFocused change its state when screen focus changes, so it would |
|||
trigger an event to query the database when screen loose focus. |
|||
But, what we want is to change its focus only when it is being |
|||
focused. |
|||
|
|||
*/ |
|||
|
|||
export default function attachFocusToQuery() { |
|||
const isFocused = useIsFocused(); |
|||
const [hasToQuery, setHasToQuery] = useState(null); |
|||
|
|||
useEffect(() => { |
|||
if (isFocused == true) { |
|||
setHasToQuery(!hasToQuery); |
|||
} |
|||
}, [isFocused]); |
|||
|
|||
return hasToQuery; |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue