看我实习多,没怎么问基础,盯着简历问
const { run, data = [], loading = false, error = '' } =useFetch(initParam,fn)
function useFetch(initParam,fn){ const [data,setData]=useState(null) const [loading,setLoading]=useState<boolean>(true) const [error,setError]=useState('') const [param,setParam]=useState(initParam) const [isRun,setRun]=useState() useEffect(()=>{ async fucntion myRequset(){ if(isRun){ try{ let res=await fn(param) if(res.status==200){ setData(res) } }catch(e){ setError(e) }finally{ setLoading(false) } } myRequset() },[isRun,param,...]) return { run:(param)=>{ setRun(true) setParam(param) }, loading, error, data } }
我这题直接用转字符串做了。
async function timer(tim) { const data = await new Promise((resolve, _) => { setTimeout(() => { resolve(tim); }, tim); }); return console.log(data); } function orderPromise2(parr) { return parr.reduce((a, b) => { return a.then(() => b()); }, Promise.resolve()); } let arr = [ () => timer(5000), () => timer(3500), () => timer(2000), () => timer(500), ]; orderPromise2(arr); async function orderPromise(parr) { for (p of parr) { await p(); } } orderPromise(arr);
最后是舔狗环节,第一次舔,不知有没有用。下来多练练,嗯我指的是,舔。
#美团前端#