如何在React Admin中获得自定义操作的响应

时间:2019-01-15 09:49:32

标签: react-admin

点击“上传”按钮后,我在react admin中调度了一个自定义操作。 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' }
});

1 个答案:

答案 0 :(得分:0)

根据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
    },
  },
});