0

How to write the call back function for this. I tried different method, but nothing seems working... I m getting Cannot read property 'props' of undefined

handleMoveToCart=(item)=>{

        this.moveCart(item, function(){
            this.props.removeFromSaveLater(item.id); //react-redux mapsDispatchToProps function
        });
}

moveCart=(item,callback)=>{
        this.props.moveToCart(item); //react-redux mapsDispatchToProps function

        callback();
}
user15006167
  • 184
  • 1
  • 3
  • 12

2 Answers2

0

you can bind this to your function where you want to use this.

Add this in constructor

this.moveCart = this.moveCart.bind(this);

Rahul Arora
  • 131
  • 2
0

works fine when replaced function(){} with ()=>

this.moveCart(item, ()=>{
            this.props.removeFromSaveLater(item.id); 
});
user15006167
  • 184
  • 1
  • 3
  • 12