How can I receive an HTTP response in the component where I dispatch the action. After the action returns the status of 200 if I console log the response I am getting the entire state's data not the actual HTTP response from my API. There are certain scenarios where I am getting dynamic success messages from API after success, which I have display using toast from my component
How can I get the actual response inside my component after dispatching an action?
Component.ts
loadHolidays() {
const param = {
holidayFor: 1,
userId: 12
};
this._store
.dispatch(new FetchHolidays(param))
.pipe(
catchError((error) => {
throw error;
})
)
.subscribe({
next: (result) => {
console.log(result);
//result returns entire state not the actual HTTP response
}
});
}
Store.ts
@Action(FetchHolidays)
fetchAllHolidays(
ctx: StateContext<CalendarStateModel>,
{ param }: FetchHolidays
) {
return this._http.post('endpoint', param).pipe(
tap((apiResult) => {
const data = apiResult.response.data;
const holidays = data.holidayLists as IHoliday[];
ctx.patchState({
holidaysList: holidays
});
})
)
}