Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,10 @@ declare module 'react-native-geocoder-reborn' {
geocodeAddress: (address: string) => Promise<GeocodingObject[]>,
};

export const useGeocodePosition: (position: Position | null) => {
geocodePosition: GeocodingObject[] | null
error: any | null
}

export default geocoder;
}
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Geocoder from './src/geocoder.js';

export { useGeocodePosition } from './src/hooks'
export default Geocoder;
22 changes: 22 additions & 0 deletions src/hooks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { useEffect, useState } from 'react'
import Geocoder from './geocoder'

export const useGeocodePosition = (position) => {
const [geocodePosition, setGeocodePosition] = useState(null)
const [error, setError] = useState(null)

useEffect(() => {
(async () => {
if (!position) return

try {
const geocodePositions = await Geocoder.geocodePosition(position)
setGeocodePosition(geocodePositions)
} catch (error) {
setError(error)
}
})()
}, [position?.lat, position?.lng])

return { geocodePosition, error }
}