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

weixin_慕虎5576974
2022-01-09
export const useArray = <P>(persons: P[]) => {
// hello,请把作业写在这里吧,写完记得再对照作业要求检查一下
const [value, setValue] = useState(persons);
const clear = () => {
setValue([]);
};
const add = (item: P) => {
setValue([
...value,
item
]);
};
const removeIndex = (index: number) => {
const newArray = value.slice()
newArray.splice(index, 1)
setValue(newArray)
};
return {
value,
clear,
add,
removeIndex
};
};
写回答
1回答
-
Nolan
2022-01-11
好 很好
00