I am working on a project in React and i am using Redux. I get a data from API and I add these data to an array. However, when I refresh the page, my data gone and my array becomes empty. Is it possible to make it permanent? How can I do that? I couldt find any example about that.
import ActionTypes from "../constants/ActionTypes";
const myCities = [];
const initialState = {
aCity: {},
};
export const WeatherReducer = (state = initialState, { type, payload }) => {
switch (type) {
case ActionTypes.GETBY_CITYNAME:
myCities.push(payload);
return { ...state, aCity: payload };
default:
return state;
}
};
CodePudding user response:
Check redux-presist library or you can use locaStorage.