File size: 1,294 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
import { useEffect } from 'react';
import {
LicenseFilter,
LicenseSortField,
LicenseSortDirection,
} from 'calypso/jetpack-cloud/sections/partner-portal/types';
import { useDispatch, useSelector } from 'calypso/state';
import { requestLicenses } from 'calypso/state/user-licensing/actions';
import { isFetchingUserLicenses } from 'calypso/state/user-licensing/selectors';
interface Props {
filter?: LicenseFilter;
search?: string;
sortField?: LicenseSortField;
sortDirection?: LicenseSortDirection;
page?: number;
}
export default function QueryJetpackUserLicenses( {
filter,
search,
sortField,
sortDirection,
page,
}: Props ): null {
const dispatch = useDispatch();
const currentlyFetchingUserLicenses = useSelector( isFetchingUserLicenses );
useEffect(
() => {
if ( ! currentlyFetchingUserLicenses ) {
dispatch( requestLicenses( filter, search, sortField, sortDirection, page ) );
}
},
// `currentlyFetchingUserLicenses` is technically a dependency but we exclude it here;
// otherwise, it would re-run the effect once the request completes,
// causing another request to be sent, starting an infinite loop.
/* eslint-disable-next-line react-hooks/exhaustive-deps */
[ dispatch, filter, search, sortField, sortDirection, page ]
);
return null;
}
|