10

Is it possible to disable optimistic UI in react-admin or is it configurable at runtime?

Ashim Saha
  • 363
  • 3
  • 9

2 Answers2

14

Disable undoable property in Edit component:

<Edit undoable={false} title={<EditTitle />} actions={<EditActions />} {...props}>
Aigars Matulis
  • 1,469
  • 17
  • 22
0

As you know undoable cannot be set on Create component. Here is a way to handle optimistic rendering if your props are different from the Create page rather than disabling it.

This is an example of handling optimistic rendering on <Show/>:

const ItemShow = (props) => {
  const record = props;
  return (
    <Show
      {...props}
    >
      <ItemCreatedScreen />
    </Show>
  );
};

const ItemCreatedScreen = ({ record }) => {
  if (record.isFromCreatePage) {
    return <Loading />;
  } else {
    return <ItemView record={record} />;
  }
};

The custom prop isFromCreatePage from the form of the Create component should help you decide if the prop is indeed from the Create page.

Optimistic Rendering will send the request to the API after a few seconds, meanwhile, the UI can show the <Loading/> sign, which is for a very short duration I might add. After which the request fetches the data from the server and this can be passed on to the <ItemView/> page.