Created
January 4, 2021 06:12
-
-
Save jwchang0206/7385b69a43ce5ddbb20fd7be001b6fa4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useCallback, useEffect } from 'react'; | |
import { useCancelTokens } from '../util/xhrHooks'; | |
import { getItems as getItemsAction } from '.'; | |
export const useItems = () => { | |
const addCancelToken, cancelAll } = useCancelTokens; | |
const getItems = useCallback(async () => { | |
// Cancel existing getItems requests before call a new one | |
cancelAll(); | |
// Get a new token for a new request | |
const cancelToken = addCancelToken(); | |
// Pass the cancel token for the request | |
return await getItemsAction({ cancelToken }); | |
}, [addCancelToken, cancelAll]); | |
return { getItems }; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment