amitpowerpeace
amitpowerpeace

Reputation: 105

Redux state is not updating into the react component

How the redux state is updated into the react component?

I tried using initial state and not mutating the object and return that

Redux 

const initialState = {
  filteredProviderData:[],
  filteredAlsoSpeaksData:[],
  filteredOfficeHours:[]

};

function reducer(state = initialState, action = {}) {
  switch (action.type) {
  case HANDLE_FILTER_CHANGE:
      let filteredProviderData = '';
      let filteredAlsoSpeaksData='';
      let filteredOfficeHours = ''
  return {...state, filteredProviderData,filteredAlsoSpeaksData,filteredOfficeHours};
  case RESET_FILTER_COLLECTION:
  // RESET the Array as shown into the HANDLE_FILTER_CHANGE
  }}
  
React component
const mapStateToProps = state => {
  return {
  filteredProviderData:state.providerList && state.providerList.filteredProviderData,
    filteredAlsoSpeaksData:state.providerList && state.providerList.filteredAlsoSpeaksData,
    filteredOfficeHours:state.providerList && state.providerList.filteredOfficeHours
  }}

Here my question is how to update the array which is into the HANDLE_FILTER_CHANGE

RESET_FILTER_COLLECTION I need to update array based on some condition and return that updated array

Here into the based on the condition only one array will be updated and return that only two would remains same.

Upvotes: 0

Views: 39

Answers (1)

Prabu samvel
Prabu samvel

Reputation: 1223

You need to change the local state once you updated the redux store. this.setState({loading:true}) Kind of approach will work and it works for me too.

Upvotes: 1

Related Questions