React DevTools force re-render button
See original GitHub issueI’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:
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:
- Created 4 years ago
- Reactions:17
- Comments:22 (7 by maintainers)
Top 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 >
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 Free
Top 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
shame this was closed, can be a useful feature
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.