react-admin: changing resource data in store without http request

点点圈 提交于 2019-12-12 10:14:49

问题


i need to modify resource data in store:

State->admin->resources->Orders->data

but without calling http request, like shown in documentation example:

// in src/comment/commentActions.js
import { UPDATE } from 'react-admin';
export const COMMENT_APPROVE = 'COMMENT_APPROVE';
export const commentApprove = (id, data, basePath) => ({
    type: COMMENT_APPROVE,
    payload: { id, data: { ...data, is_approved: true } },
    meta: { resource: 'comments', fetch: UPDATE },
});

is it possible ?


回答1:


Yes, it is possible. However, as we usually handle optimistic behaviours and other niceties, it won't be straightforward.

If you need your action type for other things (such as sagas or custom reducers):

// in src/comment/commentActions.js
import { UPDATE, FETCH_END } from 'react-admin';

export const COMMENT_APPROVE = 'COMMENT_APPROVE';

export const commentApprove = (id, data, basePath) => ({
    type: COMMENT_APPROVE,
    payload: { id, data: { ...data, is_approved: true } },
    meta: { resource: 'comments', fetchResponse: UPDATE, fetchStatus: FETCH_END },
});

If you don't:

// in src/comment/commentActions.js
import { CRUD_UPDATE_OPTIMISTIC } from 'react-admin';

export const commentApprove = (id, data, basePath) => ({
    type: CRUD_UPDATE_OPTIMISTIC,
    payload: { id, data: { ...data, is_approved: true } },
    meta: { resource: 'comments' },
});


来源:https://stackoverflow.com/questions/51099504/react-admin-changing-resource-data-in-store-without-http-request

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!