Closed ghost closed 3 years ago
Refactoring to do: setIsLoading(true)
is currently coupled to scrolling to bottom of page (in handleScroll
), but it needs to be coupled to the HTTP request in useBookSearch
.
@ArunJose found a bug: scrolling abruptly to the bottom of the page causes multiple page loads/requests. I've attempted to fix this on this branch, using @ArunJose's fix, and can't reproduce the bug. @ArunJose, can you still reproduce the bug, or is it fixed?
In console there is a warning:
React Hook useEffect has a missing dependency: 'setIsLoading'. Either include it or remove the dependency array. If 'setIsLoading' changes too often, find the parent component that defines it and wrap that definition in useCallback react-hooks/exhaustive-deps
I agree with @willnwhite that this needs refactoring. It would be a better implementation if
isLoading
state variable is declared insideuseBookSearch.jsx
and returned toApp.jsx
This is fixed by commit 6ec0771.
@ArunJose found a bug: scrolling abruptly to the bottom of the page causes multiple page loads/requests. I've attempted to fix this on this branch, using @ArunJose's fix, and can't reproduce the bug. @ArunJose, can you still reproduce the bug, or is it fixed?
@willnwhite, I can confirm this bug is fixed now 👍
@willnwhite Since you are using
setAreResultsLoading
within the hook both times, it would be better to declare it within the hook and just return theareResultsLoading
value to App.js. This will make the parameters of theuseBookSearch
hook consistant and avoid usingsetAreResultsLoading
as a dependency for useEffect inuseBookSearch
. Also, I think organising code like this will make it more modular.
Thanks @ArunJose, this is a really nice idea for a refactor.
Pair programming with @Guitarhub786