Created
September 3, 2022 14:39
-
-
Save amirrezaDev1378/9334b1ca7864145a0902803e2debef21 to your computer and use it in GitHub Desktop.
This file contains 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
function useAsync(asyncFn, onSuccess) { | |
useEffect(() => { | |
let isActive = true; | |
asyncFn().then(data => { | |
if (isActive) onSuccess(data); | |
}); | |
return () => { isActive = false }; | |
}, [asyncFn, onSuccess]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment