Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return () => {
// If there is an pending request whenever the component unmounts of the query config
// changes, cancel the pending request.
if (isPendingRef.current) {
const queryKey = getQueryKey(queryConfig);
if (queryKey) {
dispatchCancelToRedux(queryKey);
}
}
};
}, [dispatchCancelToRedux, dispatchRequestToRedux, queryConfig]);
const useMemoizedQueryConfig = (
providedQueryConfig: ?QueryConfig,
transform: (?QueryConfig) => ?QueryConfig = identity,
): ?QueryConfig => {
const [queryConfig, setQueryConfig] = React.useState(
providedQueryConfig ? transform(providedQueryConfig) : null,
);
const previousQueryKey = React.useRef(getQueryKey(providedQueryConfig));
React.useEffect(() => {
const queryKey = getQueryKey(providedQueryConfig);
if (queryKey !== previousQueryKey.current) {
previousQueryKey.current = queryKey;
setQueryConfig(providedQueryConfig ? transform(providedQueryConfig) : null);
}
}, [providedQueryConfig, transform]);
return queryConfig;
};
const dispatchRequestToRedux = useConstCallback((queryConfig: QueryConfig) => {
const promise = reduxDispatch(requestAsync(queryConfig));
if (promise) {
const queryKey = getQueryKey(queryConfig);
if (queryKey) {
pendingRequests.current.add(queryKey);
}
}
});
const prevQueryKeys = prevQueryConfigs.map(config => getQueryKey(config));
const queryKeys = queryConfigs.map(config => getQueryKey(config));
React.useEffect(() => {
const queryKey = getQueryKey(providedQueryConfig);
if (queryKey !== previousQueryKey.current) {
previousQueryKey.current = queryKey;
setQueryConfig(providedQueryConfig ? transform(providedQueryConfig) : null);
}
}, [providedQueryConfig, transform]);