← Snippets

useForceUpdate Hook

Added December 27, 2020

React hook for force a component to re-render. Useful for components which use a ref to render an external package into the DOM which React does not explicitly have control over.

1function useForceUpdate() {
2 const [value, set] = React.useState(true)
3 return () => set(!value)
4}
5