i have a default config, found through net search, and implement this in my App and it works. On my Homescreen the data is loaded and can be used. After this i need a second action which loads other data for another screen. But now is only one action available. First the data on homescreen is available and second screen get the same data, or second screen get the correct data and by switching back to homescreen there is the data from the second screen available. The Example from HomeScreen looks like:
action/index.js
export function fetchArticleDetails() {
return apiAction({
url: "requesturl",
onSuccess: setArticleDetails,
onFailure: () => console.log("Error occured loading articles"),
label: FETCH_ARTICLE_DETAILS
});
}
function setArticleDetails(data) {
return {
type: SET_ARTICLE_DETAILS,
payload: data
};
}
the reducer looks as follows
export default function(state = {}, action) {
console.log("action type => ", action.type);
switch (action.type) {
case SET_ARTICLE_DETAILS:
return { data: action.payload };
case API_START:
if (action.payload === FETCH_ARTICLE_DETAILS) {
return {
...state,
isLoadingData: true
};
}
case API_END:
if (action.payload === FETCH_ARTICLE_DETAILS) {
return {
...state,
isLoadingData: false
};
}
...
i thought, i can add a custom action with the same params as above now action/index.js added following
export function fetchPeopleList() {
return apiAction({
url: "http://wfmanager.de/appApi/2.0.0/getPeopleList/1",
onSuccess: setPeopleList,
onFailure: () => console.log("Error occured loading articles"),
label: FETCH_PEOPLELIST
});
}
function setPeopleList(data) {
return {
type: SET_PEOPLELIST,
payload: data
};
}
and reducer added following:
case SET_PEOPLELIST:
return { data: action.payload };
case API_START:
....
if (action.payload === FETCH_PEOPLELIST) {
return {
...state,
isLoadingData: true
};
}
....
case API_END:
if (action.payload === FETCH_ARTICLE_DETAILS) {
return {
...state,
isLoadingData: false
};
}
if (action.payload === FETCH_PEOPLELIST) {
return {
...state,
isLoadingData: true
};
}
Can anyone help to explain why redux overwrite the data? Many Thx.
Edit: changed reducer as suggested, but the same problem.
case SET_ARTICLE_DETAILS:
return { ...state, data: action.payload };
case SET_PEOPLELIST:
return { ...state, data: action.payload };
case API_START:
if (action.payload === FETCH_ARTICLE_DETAILS || action.payload === FETCH_PEOPLELIST) {
return {
...state,
};