Skip to content

useForceUpdate

Александр edited this page Jan 17, 2023 · 1 revision
export function useForceUpdate(): () => void

Returns a function that forcibly updates the component.

import { afc, useForceUpdate } from 'react-afc'

function Component(props) {
  const forceUpdate = useForceUpdate()

  return () => <>
    <p>Random number: {Math.random()}</p>
    <button onClick={forceUpdate}>
      Force update
    </button>
  </>
}

export default afc(Component)
Clone this wiki locally