@chaosity/location-client-react 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { GeoPlacesClient, ClientConfig } from '@chaosity/location-client';
|
|
2
|
+
export interface UseLocationClientOptions {
|
|
3
|
+
getConfig: () => Promise<ClientConfig>;
|
|
4
|
+
}
|
|
5
|
+
export declare function useLocationClient(options: UseLocationClientOptions): {
|
|
6
|
+
config: ClientConfig | null;
|
|
7
|
+
client: GeoPlacesClient | null;
|
|
8
|
+
loading: boolean;
|
|
9
|
+
error: string | null;
|
|
10
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { GeoPlacesClient } from '@chaosity/location-client';
|
|
3
|
+
export function useLocationClient(options) {
|
|
4
|
+
const [config, setConfig] = useState(null);
|
|
5
|
+
const [client, setClient] = useState(null);
|
|
6
|
+
const [loading, setLoading] = useState(true);
|
|
7
|
+
const [error, setError] = useState(null);
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
options.getConfig()
|
|
10
|
+
.then((cfg) => {
|
|
11
|
+
setConfig(cfg);
|
|
12
|
+
setClient(new GeoPlacesClient(cfg));
|
|
13
|
+
setLoading(false);
|
|
14
|
+
})
|
|
15
|
+
.catch((err) => {
|
|
16
|
+
setError(err instanceof Error ? err.message : 'Failed to initialize client');
|
|
17
|
+
setLoading(false);
|
|
18
|
+
});
|
|
19
|
+
}, []);
|
|
20
|
+
return { config, client, loading, error };
|
|
21
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { LocationClientProvider, useLocationClient } from './provider/LocationClientProvider';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { GeoPlacesClient, ClientConfig } from '@chaosity/location-client';
|
|
3
|
+
interface LocationClientContextValue {
|
|
4
|
+
config: ClientConfig | null;
|
|
5
|
+
client: GeoPlacesClient | null;
|
|
6
|
+
loading: boolean;
|
|
7
|
+
error: string | null;
|
|
8
|
+
}
|
|
9
|
+
export interface LocationClientProviderProps {
|
|
10
|
+
children: React.ReactNode;
|
|
11
|
+
getConfig: () => Promise<ClientConfig>;
|
|
12
|
+
}
|
|
13
|
+
export declare function LocationClientProvider({ children, getConfig }: LocationClientProviderProps): React.JSX.Element;
|
|
14
|
+
export declare function useLocationClient(): LocationClientContextValue;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React, { createContext, useContext, useEffect, useState } from 'react';
|
|
2
|
+
import { GeoPlacesClient } from '@chaosity/location-client';
|
|
3
|
+
const LocationClientContext = createContext(undefined);
|
|
4
|
+
export function LocationClientProvider({ children, getConfig }) {
|
|
5
|
+
const [config, setConfig] = useState(null);
|
|
6
|
+
const [client, setClient] = useState(null);
|
|
7
|
+
const [loading, setLoading] = useState(true);
|
|
8
|
+
const [error, setError] = useState(null);
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
getConfig()
|
|
11
|
+
.then((cfg) => {
|
|
12
|
+
setConfig(cfg);
|
|
13
|
+
setClient(new GeoPlacesClient(cfg));
|
|
14
|
+
setLoading(false);
|
|
15
|
+
})
|
|
16
|
+
.catch((err) => {
|
|
17
|
+
setError(err instanceof Error ? err.message : 'Failed to initialize client');
|
|
18
|
+
setLoading(false);
|
|
19
|
+
});
|
|
20
|
+
}, []);
|
|
21
|
+
return (React.createElement(LocationClientContext.Provider, { value: { config, client, loading, error } }, children));
|
|
22
|
+
}
|
|
23
|
+
export function useLocationClient() {
|
|
24
|
+
const context = useContext(LocationClientContext);
|
|
25
|
+
if (context === undefined) {
|
|
26
|
+
throw new Error('useLocationClient must be used within LocationClientProvider');
|
|
27
|
+
}
|
|
28
|
+
return context;
|
|
29
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@chaosity/location-client-react",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "React bindings for Chaosity Location Service client",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"dev": "tsc --watch",
|
|
10
|
+
"prepublishOnly": "npm run build"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"react",
|
|
14
|
+
"location",
|
|
15
|
+
"maps",
|
|
16
|
+
"geocoding",
|
|
17
|
+
"chaosity"
|
|
18
|
+
],
|
|
19
|
+
"author": "Chaosity",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@chaosity/location-client": "^0.1.0"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"react": "^18.0.0 || ^19.0.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/react": "^18.0.0",
|
|
29
|
+
"typescript": "^5.0.0",
|
|
30
|
+
"react": "^18.0.0"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist",
|
|
34
|
+
"README.md"
|
|
35
|
+
]
|
|
36
|
+
}
|