const {value, clear, removeIndex, add} = useArray([])
const useArray = <T>(initialArray: T[]) => {
const [value, setValue] = useState(initialArray)
return {
value,
setValue,
add: (item: T) => setValue([...value, item]),
clear: () => setValue([]),
removeIndex: (index: number) => {
const copy = [...value]
copy.splice(index, 1)
setValue(copy)
}
}
}