I have a weird situation at hand while trying to make a demo appointment system. I want to fetch events through Django backend rest api, which works totally fine and I could see the data coming in console as well.
Here is my index file (where provider is): https://hastebin.com/ubefumofor.js
My calendar rendering component: https://hastebin.com/oronefibap.scala
My Redux, its reduxsauce library I am using: https://hastebin.com/usetavasub.js
My ReduxSaga file: https://hastebin.com/wutuvelefi.js
Now, the thing is, I am struggling to do a few things after I fetch the events:
Where to setState, as it goes in infinite look if I call it in componentWillUpdate or componentDidUpdate?
if I use this.props.events I get the following error which I have attached as a picture. It says
uncaught at fetchEventsByDoctor The sort method cannot be invoked on an Immutable data structure.
Now I know that props cant be modified and state could be.
Any suggestions what could be wrong? Thanks
Note: I am new to react and redux related technologies.

Solution
componentDidUpdate(prevProps, prevState){
if(prevProps.events !== this.props.events) {
let a = this.state.events.slice();
let p = this.props.events
for(var i = 0; i < p.length; i++ ){
a[a.length] = p[i]
}
this.setState({events: a})
}
}
And that should do the trick, but Nagaraj's answer below is very much a good working solution too.
I have changed some things in your js file:
this.state.events.push(..is directly updating the state, which is wrong.componentWillReceivePropsto check, if the new props (nextProps) received is different than the old props (this.props), only thensetState. Usually, whenfetchEventaction is fired, set events to undefined and when you get the response, set it back to the api response in such case you can use:Like:
The Calender file: