1.1.0 • Published 8 months ago

@su-hooks/use-coords v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

@su-hooks/use-coords

React hook to get user's current coordinates

Installation

npm

npm i @su-hooks/use-coords

Usage

import React from "react";
import useCoords from "@su-hooks/use-coords";

function App() {
	const {coords, loading, error, getPosition} = useCoords();

	return (<div>
		<button onClick={getPosition}>Click Me!</button>
		<p>
			{loading ? 'loading...' : 'done!'}
		</p>
		{coords && (
			<p>lat: {coords.latitude}</p>
			<p>lon: {coords.longitude}</p>
		)}
		{error && (
			<p>error code: {error.code}</p>
			<p>error message: {error.message}</p>
		)}
	</div>)
}

Returns

Return valueTypeDescriptionDefault value
loadingBooleanA boolean representing if the Geolocation API loading.false
errorObjectAn object representing error code and error message. If you want the error code's meaning, get information from here.null
coordsObjectThis has latitude and longitude information.null
getPositionfunctionFunction wrapped around the Geolocation API's getCurrentPosition function logic.null
1.1.0

8 months ago

1.0.1

10 months ago

1.0.0

12 months ago