Why are we utilizing an unsafe method as stated in the React official docs?
" Avoid introducing any side-effects or subscriptions in this (componentWillMount()) method. For those use cases, use componentDidMount() instead."
How is react able to tell that the two Flashy components are one and the same? They are rendered by two separate calls to ReactDOM.render(). It’s hard to see how react doesn’t call componentWillLMount both times. I can understand React being able to keep track of components rendering history if those components were re-rendered by a call to setState in one of their methods, but seperate calls ReactDOM.render don’t seem to be attached to that one Flashy component.
Why do we have to use an extra anonymous function to encapsulate the this.setState in setInterval( )? I understand that setInterval needs a function as its first argument, but this.setState already satisfies this criteria. Why can’t we enter this.setState directly, without using any ( ) => { }; If anyone has an answer for this I would greatly appreciate it.
this.setState is a function. But this.setState() isn’t a function, here you are calling the setState and by calling it you are returning its return value.
And because we want to pass an argument to setState we can’t do it directly in setInterval(this.setState({})) because now we aren’t passing a function to setInterval. that’s why we are using an anonymous function to solve this problem. setInterval( () => this.setState({})) now we managed to pass a function to the setInterval also we successed to pass an argument to this.setState
They should have explained how we suddenly got the date. All it says is “new Date()” and magically we have a date time? Where did the date time come from?
In the above code what object does this refer to even though it is declared inside an arrow function ? @stetim94 Any help in understanding the various use of this would be highly appreciated.