Skip to main content

useHandleNumberFormat Hook

The useHandleNumberFormat hook provides a convenient way to format number inputs with customizable formatting options including prefix, suffix, delimiter, separator, and precision.

Examples

Default

import { useState } from 'react';
import { useHandleNumberFormat } from 'react-native-molecules/hooks';
import { TextInput } from 'react-native-molecules/components/TextInput';

const config = {
prefix: 'Rs.',
suffix: '',
separator: '.',
delimiter: ',',
precision: 2,
allowNegative: true,
};

export const Example = (props) => {
const [number, setNumber] = useState<number | null>(null);

const numberInputProps = useHandleNumberFormat({
...props,
value: number,
onChangeText: setNumber,
config,
});

return <TextInput {...numberInputProps} />;
};