useCancelButton

Returns the cancelEdit method of the data object found in the DataObjectContext

Usage

This is the implementation of the CancelButton component in the appframe-mui package.

import { forwardRef } from "react";

import { Button, ButtonProps } from "@mui/material";
import { getLocalizedString } from "@olenbetong/appframe-core";
import { useCancelButton } from "@olenbetong/appframe-react";

import Undo from "./icons/Undo.js";

export const CancelButton = forwardRef<HTMLButtonElement, ButtonProps>(
  function CancelButton(props, ref) {
    let { cancelEdit } = useCancelButton();

    return (
      <Button
        aria-label={getLocalizedString("Revert unsaved changes")}
        onClick={cancelEdit}
        startIcon={<Undo />}
        {...props}
        ref={ref}
      >
        {props.children ? props.children : getLocalizedString("Cancel")}
      </Button>
    );
  }
);

API

Last updated

Was this helpful?