I start working in a redux project with redux and it's an entirely chaos, I set up an a Store as interface, like this:
interface Store {
ads: {
loading: boolean;
data: Ad[];
errors: Error;
isPro: boolean;
};
}
interface Ad {
id: any;
title: any;
body: any;
price: any;
latitude: any;
longitude: any;
}
I have this constant to refer as an action to dispatch after:
export const TYPE_ADD_JOB_ANNOUNCEMENT_REQUEST = "action/addJobAnnouncementRequest";
And then i have my reducer:
import {
TYPE_ADD_JOB_ANNOUNCEMENT_REQUEST,
} from "../constants/actions";
export const reducer = (Store: Store, action: any) => {
switch (action.type) {
case TYPE_ADD_JOB_ANNOUNCEMENT_REQUEST:
console.log("Test");
return {
...Store,
annuncio: [...Store.ads.data, action.payload]
};
default:
console.log("dont return nothing");
break;
}
return Store;
};
I already the ReduxDevTools working, i test it with different console log and it work fine, now why when the reduxdevotools try to dispatch an action with the payload, (Example:
{
type: 'action/addJobAnnouncementRequest',
payload: { title: "test" }
}
It give me different errors if i try different test but with the same mode, like
store is undefinied,
or
cannot read property "ads"
I think there is a problem with my javascript syntax or i dont know, can anyone help me?