Skip to content

Commit

Permalink
fixed useIds not refreshing
Browse files Browse the repository at this point in the history
  • Loading branch information
SamiCharfeddine committed Dec 10, 2019
1 parent 9edfd95 commit 0522db5
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions hooks/useIds.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const setCacheStatus = (dispatch, ids, status) => {
}

function useIds(service, ids, query){
const ownRequest = useRef(false);
const [ status, setStatus ] = useState('idle');
const prevStatus = usePrevious(status);
const prevIds = usePrevious(ids);
Expand Down Expand Up @@ -53,21 +52,17 @@ function useIds(service, ids, query){

// Update cache when request is over
useEffect(() => {
if(request && ownRequest.current){
if(request){
setCacheStatus(dispatch, missingIds.current, request.status);
if(request.status !== 'pending'){
ownRequest.current = false;
}
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [dispatch, request]);
}, [request]);

// Make request to get the ids
useEffect(() => {
updateMissingIds();
if(missingIds.current.length > 0){
setCacheStatus(dispatch, missingIds.current, 'pending');
ownRequest.current = true;
dispatch(removeRequest(requestId));
const lastRequestId = dispatch(makeRequest({
method: 'GET',
Expand Down Expand Up @@ -107,7 +102,7 @@ function useIds(service, ids, query){
setItems(cacheItems);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [cacheItems]);
}, [status]);

return { items, status, setStatus };
}
Expand Down

0 comments on commit 0522db5

Please sign in to comment.