@coveord/plasma-mantine
Version:
A Plasma flavoured Mantine theme
23 lines (22 loc) • 638 B
JavaScript
import { useState } from 'react';
export const useClickWithLoading = (handler)=>{
const [isLoading, setIsLoading] = useState(false);
const handleClick = async (event)=>{
const possiblePromise = handler?.(event);
try {
if (possiblePromise instanceof Promise) {
setIsLoading(true);
await possiblePromise;
setIsLoading(false);
}
} catch (err) {
setIsLoading(false);
console.error(err);
}
};
return {
isLoading,
handleClick
};
};
//# sourceMappingURL=useClickWithLoading.js.map