Skip to content

Clamps the given value between the given minimum and maximum values.

License

Notifications You must be signed in to change notification settings

baristna/use-clamp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

useClamp react hook

npm

A React Hook to keep the given value(s) between the given minimum and maximum values.



Installation

$ yarn add use-clamp

Import

import useClamp from 'use-clamp';

Usage

const clampedValue = useClamp(value, 0, 100);

Multiple Values

With passing array of numbers as first arguments will keep sum of the values between range.

  • Each value will stay above the min value.
  • If total of the values exceeds maximum value, each values will have the weighted values.
const clampedValue = useClamp([20, 80, 50, 50], 0, 100);
// clampedValue = [10, 40, 25, 25]

About

Clamps the given value between the given minimum and maximum values.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published