Skip to content

Instantly share code, notes, and snippets.

@longfellowone
Last active February 18, 2019 22:11
Show Gist options
  • Save longfellowone/af900d55a111c1daf7237626691a73c4 to your computer and use it in GitHub Desktop.
Save longfellowone/af900d55a111c1daf7237626691a73c4 to your computer and use it in GitHub Desktop.
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