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);
标签:jira,delay,const,自定义,17,value,useArray
From: https://www.cnblogs.com/yao-655442/p/16760367.html