Created
February 6, 2019 14:13
-
-
Save fabienjuif/d791461148f271f16eb4710d37bc9c47 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import { useState } from 'react' | |
| const useRandom = (min = 0, max = Number.MAX_SAFE_INTEGER) => { | |
| const [value, setValue] = useState(undefined) | |
| const rand = () => { | |
| setValue(Math.floor(Math.random() * max) + min) | |
| } | |
| if (value === undefined) rand() | |
| return [value, rand] | |
| } | |
| export default useRandom |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
usage