Last active
June 16, 2020 14:23
-
-
Save amirfefer/23a293f728724db0f3d13c8acce01f5a to your computer and use it in GitHub Desktop.
NumericInput
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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