useRestoreWithUndoController
This hook prepares a callback for a restore button with undo support. It calls dataProvider.restoreOne() in undoable mutation mode, shows a notification, and unselects the record in the deleted records list.
This feature requires a valid Enterprise Edition subscription.
Installation
Section titled “Installation”npm install --save @react-admin/ra-core-ee# oryarn add @react-admin/ra-core-eeimport * as React from 'react';import { useRecordContext } from 'ra-core';import { useRestoreWithUndoController } from '@react-admin/ra-core-ee';
const RestoreWithUndoButton = props => { const record = useRecordContext(props); const { isPending, handleRestore } = useRestoreWithUndoController({ record, });
if (!record) return null;
return ( <button type="button" onClick={handleRestore} disabled={isPending}> Restore </button> );};Parameters
Section titled “Parameters”The hook expects an object parameter with the following properties:
record: The deleted record to restore. Required whenhandleRestoreis called.mutationOptions:react-querymutation options (supportsmeta).successMessage: A custom notification message key.onClick: A callback called after the mutation is triggered.
TypeScript
Section titled “TypeScript”The useRestoreWithUndoController hook accepts a generic parameter for the record type and another for the error type:
useRestoreWithUndoController<Product, Error>({ record, mutationOptions: { onError: error => { // TypeScript knows that error is of type Error }, },});