Skip to content

Instantly share code, notes, and snippets.

@amirfefer
Last active June 16, 2020 14:23
Show Gist options
  • Save amirfefer/23a293f728724db0f3d13c8acce01f5a to your computer and use it in GitHub Desktop.
Save amirfefer/23a293f728724db0f3d13c8acce01f5a to your computer and use it in GitHub Desktop.
NumericInput
const [size, setSize] = useState(0);
const GB_SIZE_IN_BYTE = 1000000000;
const MB_SIZE_IN_BYTE = 1000000;
const Example = () => {
const formaatedSize = useCallback(() => {
switch (true) {
case 0 <= size < GB_SIZE_IN_BYTE:
return { type: 'MB', value: size / MB_SIZE_IN_BYTE };
case size >= GB_SIZE_IN_BYTE:
return { type: 'GB', value: size / GB_SIZE_IN_BYTE };
}
}, [size]);
const formatedValue = formaatedSize().value;
const formatedType = formaatedSize().type;
return (
<Numeric
onChange={onchange}
value={formatedValue}
format={() => `${formatedValue} ${formatedType}`}
/>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment