react-native-scrollable-tabview icon indicating copy to clipboard operation
react-native-scrollable-tabview copied to clipboard

useRefreshEndReached onRefresh no update

Open HowardTangHw opened this issue 2 years ago • 3 comments

根据代码

export const onRefresh = (screen, callback) => {
  if (!refreshMap.has(screen)) {
    refreshMap.set(screen, callback);
  }
}

后续如果callback发生了改变,也不会重新更新 譬如

const usePatchData =(type)=>{
  function onRefreshPatchData(){
    console.log(type);
  }
  return [onRefreshPatchData];
}


const [type,setType]=useState('A');
const [onRefreshPatchData] = usePatchData(type);


onRefresh((toggled) => {
  onRefreshPatchData();
  // 当type无论怎么变化
  // log出来都会是'A'
};
```

HowardTangHw avatar Apr 04 '23 05:04 HowardTangHw

@HowardTangHw @itenl 这个问题有解决办法吗?我也碰到了这个问题,感觉是个大坑,useRefreshEndReached 里面所有的方法都有这个问题

chachaxw avatar Apr 25 '23 08:04 chachaxw

@chachaxw 我的解决方法是这样的

const usePatchData =(type)=>{
  const [count,setCount]=useState(0);
  useEffect(()=>{
    // call api on this line
    console.log(type);
   },[count])


  function onRefreshPatchData(){
    setCount(pre=>pre+1);
  }
  return [onRefreshPatchData];
}


const [type,setType]=useState('A');
const [onRefreshPatchData] = usePatchData(type);


onRefresh((toggled) => {
  onRefreshPatchData();
}

需要加上一些checking,因为会比较频繁的调用到onRefreshPatchData

HowardTangHw avatar Apr 25 '23 15:04 HowardTangHw

@HowardTangHw 我这边有个问题就是,调用 onReachEnd 方法的时候,回调函数执行有点奇怪,本来是加载更多数据,有时候能加载,有时候又加载不出来

chachaxw avatar Apr 26 '23 06:04 chachaxw