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-2mhlylm9n

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;