How to disable optimistic UI updates in react-admin?
Asked Answered
A

2

10

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

Anthropology answered 12/6, 2018 at 1:46 Comment(0)
I
14

Disable undoable property in Edit component:

<Edit undoable={false} title={<EditTitle />} actions={<EditActions />} {...props}>
Interracial answered 18/6, 2018 at 16:51 Comment(5)
is there a way to set undoable={false} for all forms globally? ThanksPodgorica
create your own component based on Edit component and set undoable property to false by defaultInterracial
yeah I thought of that I would expect that I could just pass undoable={false} in <Admin>Podgorica
if you want to have your undoable always to be false, create an Edit component with the undoable props set to false, and instead of importing the Edit component from react-admin all the time, you import your newly created Edit component.Companionable
I want to turn optimized rendering off for a Show page too, but passing undoable={false} does not work.Roark
H
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.

Hefter answered 28/5, 2020 at 8:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.