Skip to main content

useForceUpdate

A custom hook that forces the component to re-render when the returned function is executed.


Interface

// type DispatchWithoutAction = () => void;
const useForceUpdate: () => React.DispatchWithoutAction

Usage

import { useForceUpdate } from '@devgrace/react';

const Example = () => {
const forceUpdate = useForceUpdate();

const handleForceUpdate = useCallback(() => {
forceUpdate();
}, [forceUpdate]);

return (
<div>
<button onClick={handleForceUpdate}>Button</button>;
</div>
);
};

Note

https://github.com/streamich/react-use/pull/837