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.

React DevTools force re-render button

See original GitHub issue

I’d like to have a button that forces a re-render of the selected component when clicked. For example, adding a button like this on the right of the component controls:

image

This can be accomplished today by adding a new prop and changing the prop, but it’s more work than I want to do.

This would be useful for use while profiling how a component performs with unnecessary re-renders. Right now I just have a button that’s tied to a “forceRender” function:

function useForceRerender() {
  const [, set] = React.useState()
  return React.useCallback(() => set({}), [])
}

function FilterComponent() {
  const forceRerender = useForceRerender()
 
  return (
    <>
      <button onClick={forceRerender}>force rerender</button>
      {/* more JSX */}
    </>
  )
}

Would be cool to have this built-in 😃

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:17
  • Comments:22 (7 by maintainers)

github_iconTop GitHub Comments

16reactions
giotisklcommented, Sep 18, 2020

shame this was closed, can be a useful feature

8reactions
sliktscommented, Feb 27, 2020

An another use case for a feature like this is checking if effects are correctly memoized and cleaned up, so it’s not just about rerenders.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Force a React Component to Re-Render
Note: In most cases you should never force a React component to re-render; re-rendering should always be done based on state or props...
Read more >
React forcing a full re-render on button click - Stack Overflow
The issue here is with <a /> element. You can use the button instead of <a /> as on click anchor tag execute...
Read more >
How and when to force a React component to re-render
React automatically re-renders components, but what happens when a component is not updating as expected? Find out what you can do here.
Read more >
When does React re-render components? - Felix Gerschau
In React hooks, the forceUpdate function isn't available. You can force an update without altering the components state with React.useState like ...
Read more >
How To Debug React Components Using React Developer ...
In this step, you'll install the React Developer Tools broswer extension in Chrome. You'll use the developer tools in the Chrome JavaScript ...
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