Skip to main content

useForceUpdate

Importing useForceUpdate Hook​

import { useForceUpdate } from '@ciceksepeti/cui-hooks';

Example​

import React, { useRef } from 'react';
import { useForceUpdate } from '@ciceksepeti/cui-hooks';

export const Example = () => {
const ref = useRef({ count: 0 });
const forceUpdate = useForceUpdate();

return (
<div>
<p>Count: {ref.current.count}</p>
<button onClick={() => ref.current.count++}>increment</button>
<button onClick={() => forceUpdate()}>force update</button>
</div>
);
};

Preview & Test​

PREVIEW & TEST AREA
useForceUpdate
  • Increment or Decrement buttons will not update the referenced count number unless user use Force Update button.

First Ref Count: 0

Second Ref Count: 0