I need to sort out the data in the state for the first time after lifting the ban on anything, besides, I didn’t succeed. I want to see what is in the “changeable drafts” and “diary entries”, but console.log() does not work to update the query data. only two requests were launched. console.log(current()), when I don’t get any results after the request, the getState() call is started.getAllDiaryEntries is not defined.
Updated DiaryEntry: builder.mutation({ request: ({id, data }) => ({ url: diaryEntries/${id}, method: ‘PUT’, body: data, }), invalid tags: [‘DiaryEntry’], asynchronous launch onQueryStarted({ id, data }, { sending, request completed }) { console.log(data);
Мне необходимо обновить данные в state сразу после отправки на сервер чтобы небыло задержки, однако у меня ничего не просиходит.
Я хочу посмотреть что находится в переменных draft” и “diaryEntry” однако console.log() не работает внутри updateQueryData. только если внутри onQueryStarted. console.log(current()) так же не дает никаких результатов а попытка внутри onQueryStarted вызвать getState().getAllDiaryEntries дает undefined.
updateDiaryEntry: builder.mutation({
query: ({ id, data }) => ({
url: diaryEntries/${id}
,
method: ‘PUT’,
body: data,
}),
invalidatesTags: [‘DiaryEntry’],
async onQueryStarted({ id, data }, { dispatch, queryFulfilled }) {
console.log(data);
const patchResult = dispatch(
api.util.updateQueryData('getAllDiaryEntries', data, (draft: any) => {
const diaryEntry = draft.find((entry) => entry._id === id);
Object.assign(diaryEntry, data);
})
);
try {
await queryFulfilled;
} catch {
patchResult.undo();
}
},
}),
Fedor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.