Created
September 22, 2019 07:55
-
-
Save drublic/e7736ac2773708e0190c7722d0012c88 to your computer and use it in GitHub Desktop.
Custom Hook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Testable Custom Hooks | |
import { useEffect } from "react"; | |
// Function that can be tested with clear API, easily unit-testable | |
const handleHasLoader = ({ isLoading, hasFocus, setHasLoader }) => { | |
if (isLoading && !hasFocus) { | |
return setHasLoader(true); | |
} | |
return setHasLoader(false); | |
}; | |
// Custom Hook implementing effect | |
const useHasLoader = ({ isLoading, hasFocus, setHasLoader }) => { | |
useEffect( | |
() => | |
handleHasLoader({ isLoading, hasFocus, setHasLoader }), | |
[isLoading, hasFocus, setHasLoader], | |
); | |
}; | |
export default useHasLoader; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment