Created
October 23, 2020 08:55
-
-
Save tpjnorton/ca4a66c4981691e8e7c0900a3248b8a9 to your computer and use it in GitHub Desktop.
useLoading.ts
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
import { useState } from "react"; | |
const useLoading = (action) => { | |
const [loading, setLoading] = useState(false); | |
const doAction = (...args) => { | |
setLoading(true); | |
return action(...args).finally(() => setLoading(false)); | |
}; | |
return [doAction, loading]; | |
}; | |
export default useLoading; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment