rud167637
@rud1676371262
Reviews Written
1
Average Rating
5.0
Posts
Q&A
REQUEST를 실행해도 loadPostLoading이 바로 바뀌지 않습니다.
저도 같은 에러엿는데 도움많이됫습니다!제 추측이지만 addEventListner한 상태에서dispatch가 비동기로 실행되는 동안 빠른시간내에 scroll이벤트를 두번 부른거 같더라구요 그래서 onec라는 변수를 둬서 useEffect실행되기 전에 한번만 실행하게끔 했더니 깔끔하게 REQUEST를 한번만 실행했습니다. useEffect(() => { let onec = false; function onScroll() { const scrollpos = window.scrollY + document.documentElement.clientHeight; if (scrollpos > document.documentElement.scrollHeight - 300) { if (hasMorePosts && !LoadPostLoading && !onec) { onec = true; console.log('LOADPOSTLOADING', LoadPostLoading); console.log('hasmor', hasMorePosts); dispatch({ type: LOAD_POST_REQUEST, }); } } } window.addEventListener('scroll', onScroll); return () => { window.removeEventListener('scroll', onScroll); }; }, [hasMorePosts, LoadPostLoading]);
- 0
- 2
- 387
Q&A
user를 찾을 수 없다고 나와요ㅠㅠㅠㅠ
감사합니다 저도 이거때문에 애먹고있었는데 ㅋㅋ
- 8
- 8
- 509




