2-1、要求
自定义一个useArray的custom hook。结合react-hook和typescript,实现对数组简单的增加、删除、清空的那个功能,并且对增加的对象类型有限制
2-2、代码实现
export const useDebounce = (value, delay) => {
const [debounceValue, setDebounceValue] = useState(value);
useEffect(() => {
const timer = setTimeout(() => {
setDebounceValue(value);
}, delay);
return () => clearTimeout(timer);
}, [value, delay]);
return debounceValue;
};
const { value, clear, removeIndex, add } = useArray(initValue);
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
武汉格发信息技术有限公司,格发许可优化管理系统可以帮你评估贵公司软件许可的真实需求,再低成本合规性管理软件许可,帮助贵司提高软件投资回报率,为软件采购、使用提供科学决策依据。支持的软件有: CAD,CAE,PDM,PLM,Catia,Ugnx, AutoCAD, Pro/E, Solidworks 等。