useSaveButton
Returns a save function and dirty/isSaving statuses for the data object found in the DataObjectContext
Usage
This is the implementation of the SaveButton component in the appframe-mui package.
import { forwardRef } from "react";
import Save from "./icons/Save.js";
import { Badge, Button, ButtonProps } from "@mui/material";
import { getLocalizedString } from "@olenbetong/appframe-core";
import { useSaveButton } from "@olenbetong/appframe-react";
export const SaveButton = forwardRef<HTMLButtonElement, ButtonProps>(
function SaveButton(props, ref) {
let { dirty, isSaving, save } = useSaveButton();
return (
<Button
loading={isSaving}
onClick={save}
loadingPosition="start"
startIcon={
<Badge invisible={!dirty} color="secondary" variant="dot">
<Save />
</Badge>
}
{...props}
ref={ref}
>
{props.children ? props.children : getLocalizedString("Save")}
</Button>
);
}
);API
Last updated
Was this helpful?