Skip to content

Instantly share code, notes, and snippets.

@gabrielyotoo
Created October 24, 2024 20:46
Show Gist options
  • Save gabrielyotoo/33b51f7f1246d7e9a6b407b76a6f37c7 to your computer and use it in GitHub Desktop.
Save gabrielyotoo/33b51f7f1246d7e9a6b407b76a6f37c7 to your computer and use it in GitHub Desktop.
MUI Loading Button
import { Button, ButtonProps, CircularProgress } from '@mui/material';
import { useMemo } from 'react';
type LoadingButtonProps = ButtonProps & {
isLoading?: boolean;
};
const LoadingButton = ({ isLoading = false, ...props }: LoadingButtonProps) => {
const loadingProps = useMemo<ButtonProps>(() => {
if (loading) {
return {
endIcon: <CircularProgress color="grey" size={18} />,
disabled: true,
};
}
return {};
}, [loading]);
return <Button {...props} {...loadingProps} />;
};
export default LoadingButton;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment