use-force-update

Forces the component to rerender without state change

Import

Usage

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

mantine-765170hzz

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;