Created
December 5, 2020 16:10
-
-
Save fauxsaurus/c0314b3b498c6696017981e426a7232b to your computer and use it in GitHub Desktop.
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
import {useState} from 'react'; | |
export const useVector = <T>(initialValue: T, arity = 3) => { | |
const [vector, setVector] = useState<T[]>([...Array(arity)].fill(initialValue)); | |
const updateVector = (newValue: T) => setVector([newValue].concat(vector.slice(1))); | |
return [vector, updateVector] as const; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment