问题
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