From some reason I am not able to detect changes in props in ComponentDidUpdate().
Parent Component:
class Parent extends Component{
componentDidUpdate(prevProps,prevState){
// here, prevProps is the same as this.props even though the
// consultations object is changed by the date component
}
render(){
return(
<p>{this.props.consultation.date}</p> /* Changes when date
component changes the date. This works! */
<DateComponent />
);
}
}
function mapStateToProps({consultation}){
return {consultation}
}
export default connect(mapStateToProps, null)(Parent)
The Date Component is used to change the consultation date. I made sure I don't mutate the state in the reducer and return a new object using Object.assign().
The date in the 'p tag' changes perfectly when the consultation date is changed by the DateComponent
In ComponentDidUpdate, prevProps.consultation.date & this.props.consultation.date are equal.
Both have the new date value! I thought prevProps.consultation.date would give me the older date!
I am stuck because I am not able to detect the change in date and perform necessary actions in ComponentDidUpdate().
I would be really grateful to any one who can shed some light on where I could be going wrong.
Thank you all.
Edit: ****Reducer code as requested****
case DATE_CHANGE_SUCCESS:
var consultation = {...state}
consultation.date = action.data.date;
return Object.assign({},state,{consultation});