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

a 夏天 提交于 2019-12-08 13:32:33

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