Reputation: 11
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 ?
Upvotes: 1
Views: 494
Reputation: 7066
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' },
});
Upvotes: 2