Last active
February 18, 2019 22:11
-
-
Save longfellowone/af900d55a111c1daf7237626691a73c4 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
export const useGrpcRequest = (func, setState) => { | |
const [params, setParams] = useState(null); | |
useEffect(() => { | |
let unmounted = false; | |
(async () => { | |
try { | |
if (!params) return; | |
const result = await func(params); | |
if (unmounted) return; | |
setState(result); | |
} catch (error) {} | |
})(); | |
return () => { | |
unmounted = true; | |
}; | |
}, [params]); | |
return params => setParams(params); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment