use-force-update

Force component to rerender without state change

Import

Usage

use-force-update returns a function, which when called rerenders the component:

mantine-pnoyw6kr6

import { Button, Text, Group } from '@mantine/core';
import { useForceUpdate, randomId } from '@mantine/hooks';

function Demo() {
  const forceUpdate = useForceUpdate();

  return (
    <Group justify="center">
      <Text>{randomId()}</Text>
      <Button onClick={forceUpdate}>Force update</Button>
    </Group>
  );
}

Definition

function useForceUpdate(): () => void;