In a component that does not override shouldComponentUpdate, is there a difference between forceUpdate and setState?
Update: I already know what the docs say, and that forceUpdate is not recommended for this. I'm just trying to get a deeper understanding of what is happening. I would like to know why? And I already know that setState combines the passed object (state "delta" - sort of like updating sql) with the current state object.
Suppose a simple use case: there is no need for a cancel function or time. No need to do pointer comparisons inside shouldComponentUpdate. Actually, you should not use shouldComponentUpdate at all.
In this case, it seems to me that the mutating state and the calling force of Update () is a perfectly acceptable way to use React. From a black box perspective, these two methods have the same effect:
Technique No. 1: this.state.x = 10; this.forceUpdate ();
Technique No. 2: this.state.setState ({x: 10});
Again, I already know that some people prefer never to mutate a state. And use the style of functional programming. I'm just wondering if there are any technical reasons to avoid Technique No. 1. Or am I missing something?
source share