File size: 498 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { useQuery } from '@tanstack/react-query';

export interface GeoLocationData {
	city: string;
	country_long: string;
	country_short: string;
	latitude: string;
	longitude: string;
	region: string;
}

export const useGeoLocationQuery = ( options = {} ) =>
	useQuery< GeoLocationData >( {
		queryKey: [ 'geo' ],
		queryFn: () =>
			fetch( 'https://public-api.wordpress.com/geo/' ).then( ( response ) => response.json() ),
		staleTime: Infinity,
		meta: { persist: false },
		...options,
	} );