forceUpdate in react not a valid comparison?
See original GitHub issueI noticed in react there’s this code
swapRows = () => {
const data = this.state.data;
if (data.length > 998) {
let temp = data[1];
data[1] = data[998];
data[998] = temp;
}
this.forceUpdate();
}
Why is that not the same as react hooks? as in
swapRows = () => {
const data = this.state.data;
if (data.length > 998) {
this.setState({ data: [data[0], data[998], ...data.slice(2, 998), data[1], data[999]] })
}
}
Same for update
and remove
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
In React, what is the difference between setState and ...
The forceUpdate() function is just a way to force a re-render of the component and its children in question. It does not mutate...
Read more >Hooks FAQ - React
Is there something like forceUpdate? ... Both useState and useReducer Hooks bail out of updates if the next value is the same as...
Read more >Wild React : useForceUpdate() - Medium
The useForceUpdate() hook isn't quite a 1-to-1 comparison with the forceUpdate() class component usage above. That's because there's no ...
Read more >React.Component
shouldComponentUpdate() is invoked before rendering when new props or state are being received. Defaults to true This method is not called for the...
Read more >What is Render in React and How Do You Force it? - Telerik
If you are using a React class component then it is as easy as using this.forceUpdate() function. ... Just make sure that the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Should this be closed since #869 merged?
Absolutely!