Functions reference

This guide contains a list of functions exported from Mantine packages that are not documented elsewhere.

clamp

The clamp function is exported from @mantine/hooks. It clamps a number within the inclusive lower and upper bounds.

import { clamp } from '@mantine/hooks';

// With both min and max boundaries
clamp(10, 0, 5); // 5
clamp(100, 0, 5); // 5
clamp(-100, 0, 5); // 0

// With only min boundary
clamp(10, 0, undefined); // 10
clamp(-100, 0, undefined); // 0

// With only max boundary
clamp(0, undefined, 5); // 0
clamp(10, undefined, 5); // 5

lowerFirst

The lowerFirst function is exported from @mantine/hooks. It converts the first character of a string to lowercase.

import { lowerFirst } from '@mantine/hooks';

lowerFirst('Mantine'); // mantine
lowerFirst('mantine'); // mantine

upperFirst

The upperFirst function is exported from @mantine/hooks. It converts the first character of a string to uppercase.

import { upperFirst } from '@mantine/hooks';

upperFirst('Mantine'); // Mantine
upperFirst('mantine'); // Mantine

randomId

The randomId function is exported from @mantine/hooks. It generates a random id with the mantine- prefix.

import { randomId } from '@mantine/hooks';

randomId(); // mantine-d7h137oav
randomId(); // mantine-1q2j3j4j5

range

The range function is exported from @mantine/hooks. It generates an array of numbers from start to end (inclusive).

import { range } from '@mantine/hooks';

range(0, 5); // [0, 1, 2, 3, 4, 5]
range(5, 0); // [5, 4, 3, 2, 1, 0]

shallowEqual

The shallowEqual function is exported from @mantine/hooks. It performs a shallow equality check of two objects.

import { shallowEqual } from '@mantine/hooks';

shallowEqual({ a: 1 }, { a: 1 }); // true
shallowEqual({ a: 1 }, { a: 2 }); // false