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

害羞的西红柿
2021-07-27
const useArray=<T>(param: T[]) => {
const [value, setValue] = useState(param);
// 删除
const clear = () => {
setValue([]);
};
// 移除一项
const removeIndex: (index: number) => void = (index) => {
const copyData = [...value];
copyData.splice(index,0);
setValue([...copyData]);
};
return {
clear,
add: (item: T) => setValue([...value, item]),
removeIndex,
value,
};
};
写回答
2回答
-
Nolan
2021-07-28
Very good
00 -
Nolan
2021-07-28
Very good
00