直接上代码吧,类似于之前class组件this.setState的第二个callback参数importReact,{useState,useEffect}from'react';importfetchDatafrom'services';functionuseList(){const[params,setParams]=useState({});const[data,setData]=useState({});constgetData=()=>{fetchData(params).then(res=>{setData(res);});};useEffect(()=>{getData();},[]);return{params,setParams,data,setData,getData,};}functionFoo(){const{setParams,getData}=useList();consthandleClick=()=>{setParams({mockData:2333333});//如何让getData里params是最新的???getData();};return(clickme);}
添加回答
举报
0/150
提交
取消