如何在反应管理员中获得自定义操作的响应

How to get a response of custom action in react admin

单击“上传”按钮后,我在 React 管理员中发送了一个自定义操作。 POST 请求成功,但我不知道如何得到响应。我记录了每个 reducer 调用,但那里没有响应数据。我的操作示例:

export const UPLOAD_BY_BASE64 = 'UPLOAD_BY_BASE64';
export const uploadByBase64 = ({ file, path }) => ({
  type: UPLOAD_BY_BASE64,
  payload: { file, path },
  meta: { fetch: CREATE, resource: 'images/upload/base64' }
});

根据 Handling Side Effects documentation,您可以将回调传递给 meta 属性以检索响应负载:

export const uploadByBase64 = ({ file, path }) => ({
  type: UPLOAD_BY_BASE64,
  payload: { file, path },
  meta: {
    fetch: CREATE,
    resource: 'images/upload/base64',
    callback: ({ payload, requestPayload }) => {
      // payload = response payload
    },
  },
});