import { useCallback, useState } from 'react'

/**
 * Hook that provides a function to force a component to re-render. Returns a tuple of `[rerender
 * function, rerender count]`.
 */
export function useForceRerender() {
  const [rerenderCount, setRerenderCount] = useState(0)
  const rerender = useCallback(() => {
    setRerenderCount((count) => count + 1)
  }, [])
  return [rerender, rerenderCount] as const
}
