Skip to main content

useForceUpdate

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


Code

🔗 View source code


Interface

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

Usage

typescript
import { useForceUpdate } from '@modern-kit/react';

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

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

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

Remarks