File size: 346 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import { useState } from 'react'
import { useIsMounted } from './useIsMounted'

/** Return a function that re-renders this component, if still mounted */
export function useForceUpdate() {
  const update = useState<any>()[1]
  const isMounted = useIsMounted()
  return () => {
    if (isMounted.current) {
      update(Math.random())
    }
  }
}