Legendary

李洋的学习笔记


utils.js

<pre><code>import {useState,useRef,useEffect,useCallback} from 'react' export function deepClone(obj={}){ let newObj = null; if(typeof(obj) === 'object' &amp;amp;&amp;amp; obj !== null){ newObj = obj instanceof Array ? [] : {} for(let k in obj){ newObj[k] = deepClone(obj[k]) } } else{ newObj = obj } return newObj } export function useDebounce(fn,delay,dep=[]){ const {current} = useRef({ fn, timer:null, }) useEffect(()=&amp;gt;{ current.fn = fn },[fn]) return useCallback(function f(...args){ if(current.timer){ clearTimeout(current.timer) } current.timer = setTimeout(()=&amp;gt;{ current.fn.call(this,...args) },delay) },dep) } export function useThrottle(fn,delay,dep=[]){ const {current} = useRef({ fn, timer:null }) useEffect(()=&amp;gt;{ current.fn = fn },[fn]) return useCallback(function f(...args){ if(!current.timer){ current.timer = setTimeout(()=&amp;gt;{ delete current.timer },delay) current.fn.call(this,...args) } },dep) }</code></pre>

页面列表

ITEM_HTML