File size: 897 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
import { useEffect } from 'react';
import { useDispatch, useSelector } from 'calypso/state';
import { requestLicensesCounts } from 'calypso/state/user-licensing/actions';
import { isFetchingUserLicensesCounts } from 'calypso/state/user-licensing/selectors';

export default function QueryJetpackUserLicenses(): null {
	const dispatch = useDispatch();
	const currentlyFetchingUserLicensesCounts = useSelector( isFetchingUserLicensesCounts );

	useEffect(
		() => {
			if ( ! currentlyFetchingUserLicensesCounts ) {
				dispatch( requestLicensesCounts() );
			}
		},
		// `currentlyFetchingUserLicensesCounts` 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 ]
	);

	return null;
}