4-6 作业提交
来源:4-6 作业练习 - 用 Hook + TS + TS泛型实现useArray

raymondJ
2021-11-29
export const useArray = (array: T[]) => {
// hello,请把作业写在这里吧,写完记得再对照作业要求检查一下
const [value, setValue] = useState(array)
const clear = () => {
setValue([])
}
const removeIndex = (index: number) => {
if (index >= value.length) return
const newValue = […value.slice(0, index), …value.slice(index + 1)]
setValue(newValue)
}
const add = (object: T) => {
setValue([…value, object])
}
return { value, clear, removeIndex, add }
}
写回答
1回答
-
Nolan
2021-12-04
Good
00