I am kinda bumped because it used to work automatically when you are using connect api from react-redux. But now I am facing a situation where some data is not getting updated when something gets returned from reducer..
this is my pseudo code..
in the reducer file I have..
case "SORT_BY_DATE":
let startDateSort = state.startDateSort;
let endDateSort = state.endDateSort;
const sortByStartDateUp = function(a, b) {
return new Date(a.start_date) > new Date(b.start_date) ? 1 :-1;
}
const sortByStartDateDown = function(a, b) {
return new Date(b.start_date) > new Date(a.start_date) ? 1:-1;
}
const sortByEndDateUp = function(a, b) {
return new Date(a.stop_date) > new Date(b.stop_date) ? 1 : -1;
}
const sortByEndDateDown = function(a, b) {
return new Date(b.stop_date) > new Date(a.stop_date) ? 1 : -1;
}
let sortFunctionByDate = "";
if (action.time == "start"){
sortFunctionByDate = startDateSort == true ? sortByStartDateUp : sortByStartDateDown;
startDateSort = !startDateSort;
}else{
sortFunctionByDate = endDateSort == true ? sortByEndDateUp : sortByEndDateDown;
endDateSort = !endDateSort;
}
let filtered = state.status + "Banners";
let banners_filtered =state['banners'].sort(sortFunctionByDate)
state[filtered] = banners_filtered;
state["banners"] = banners_filtered
return Object.assign({}, state, {
startDateSort,
endDateSort,
showImageButton: false,
})
Up to here I was able to assert that I am getting correct info. from the banners_filtered variable.
this is my container component:
const mapStateToProps = (state) => {
let {liveBanners} = state.BannerReducer;
console.log("liveBanners", liveBanners)
return {
liveBanners
}
}
const BannerTableList = connect(mapStateToProps,mapDispatchToProps(BannerTable)
----I was able to log liveBanners here..as well--- But this value is not getting updated in the dumb compononent..like other variables I have been doing...Could it be because there is too much? computation inside the reducer? I hardly doubt that is the reason. But if you have any hunch what could have gone wrong please let me know. I am all ears at this point.. thanks.
--also there is no error shown in the console --- ---more code update--
const BannerTable = ({liveBanners}) => {
console.log("banners", liveBanners)
}
above is my dumb component using stateless function and liveBanners never logged in the console.