loading messages
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import { useCallback } from "react";
|
||||
import { useGlobal } from "reactn";
|
||||
|
||||
const useGlobalLoading = () => {
|
||||
const [, setIsLoading] = useGlobal("_isLoading");
|
||||
const [, setLoadingMessage] = useGlobal("_loadingMessage");
|
||||
|
||||
const setLoading = useCallback(
|
||||
async (loading, { message } = {}) => {
|
||||
if (loading) {
|
||||
await setLoadingMessage(message ?? null);
|
||||
await setIsLoading(true);
|
||||
} else {
|
||||
await setIsLoading(false);
|
||||
await setLoadingMessage(null);
|
||||
}
|
||||
},
|
||||
[setIsLoading, setLoadingMessage]
|
||||
);
|
||||
|
||||
return {
|
||||
setLoading,
|
||||
setLoadingMessage,
|
||||
};
|
||||
};
|
||||
|
||||
export default useGlobalLoading;
|
||||
Reference in New Issue
Block a user