Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useRefreshEndReached onRefresh no update #33

Open
HowardTangHw opened this issue Apr 4, 2023 · 3 comments
Open

useRefreshEndReached onRefresh no update #33

HowardTangHw opened this issue Apr 4, 2023 · 3 comments

Comments

@HowardTangHw
Copy link

根据代码

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'
};
```

@chachaxw
Copy link

chachaxw commented Apr 25, 2023

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

@HowardTangHw
Copy link
Author

HowardTangHw commented Apr 25, 2023

@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

@chachaxw
Copy link

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

Repository owner deleted a comment from muhammadmnorouzi Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants