question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

forceUpdate in react not a valid comparison?

See original GitHub issue

I 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:closed
  • Created 3 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
mrienstracommented, Apr 12, 2021

Should this be closed since #869 merged?

0reactions
krausestcommented, Apr 20, 2021

Absolutely!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found