0

Redux store changes but component does not get rendered ,when user login and we are returned back to product component Redux store does not update component and its props

class Product extends React.Component {
    onClickAdd(){
      if(!user) {
        this.props.navigation.navigate('login')
        return;
      }
      this.addTaskTocart()
    }
    
    render() {
      return ()
    }
}
const mapStateToProps = (state) => {
      const {  cart } = state;  
      return {  cart: cart  }
};
    
const mapDispacthToProps = dispatch => {
  return {
    getCartItems: () => dispatch(getCartItems())
  };
}
    
export default connect(mapStateToProps, mapDispacthToProps)(Product)
  • what is `user`? What is `Product`? – nithinpp Sep 07 '21 at 05:49
  • 1
    Maybe you are mutating state in the reducer. You should check what actions are dispatched and what changes they made (redux devtools) and then see what code is executed (consle.log) and when. – HMR Sep 07 '21 at 06:06
  • User is userID from async storage and product is products array @nithinpp – shabaz-tech Sep 07 '21 at 07:32
  • const authReducer = ( state = INITIAL_AUTH_STATE, action ) => { switch(action.type){ case AUTH : // console.log(action) return{ ...state, authData : action.payload } case LOGOUT : return{ ...state, authData : [] } default: return state; } } – shabaz-tech Sep 07 '21 at 07:33
  • const cartReducer = (state = INITIAL_CART_STATE, action) => { switch (action.type) { case CART_FETCH_SUCCESS: return { ...state, cartData: action.cartData } case ADD_CART_DATA: case REMOVE_CART_DATA: return { ...state, cartData: action.cartData } case RESET_CART_COUNT: state.cartData = []; return {...state, ...{cartData: []}}; default: return state; } } – shabaz-tech Sep 07 '21 at 07:33
  • those are my reducers , i guess they are not getting mutated @HMR – shabaz-tech Sep 07 '21 at 07:34
  • I don't see a `product` array in your code. You are wrapping some `Product` component with `connect HOC`, when your components name is `Welcome ` – nithinpp Sep 07 '21 at 07:34
  • That was error bymiss i gave the name wrong , am trying to check if user is logged in or not on click , Am directing it to login if user not logged in , and returning back to the same screen , here redux store gets updated but product component does not re-render, if the store changes – shabaz-tech Sep 07 '21 at 11:28

0 Answers0