UNPKG

usegeoaddress

Version:

usegeoaddress is a lightweight npm package that retrieves users' current location, including city, district, and region details. It also handles location permission errors seamlessly for a smooth user experience.

74 lines (47 loc) 1.77 kB
# usegeoaddress Hook ## Description The usegeoaddress hook is a custom hook that allows retrieving the user's geolocation address using the browser's Geolocation API. This hook simplifies the process of fetching and managing the address information associated with a given latitude and longitude. ## Installation To install the usegeoaddress hook, follow these steps: Make sure you have React installed in your project. $ npm install react Install the usegeoaddress hook using npm or yarn. ```bash $ npm install usegeoaddress ``` ```bash $ yarn add usegeoaddress ``` ## Usage ### Here's an example of how to use the usegeoaddress hook in a React file: ```javascript import React from "react"; import usegeoaddress from "usegeoaddress"; function App() { const { address, err, status } = usegeoaddress(); if (err) { return <div>Error: {err.message}</div>; } if (status !== "granted") { return <div>Permission to access location was denied</div>; } if (!Address) { return <div>Loading...</div>; } return ( <div> <h1>Address Details</h1> <p>Street: {address.street}</p> <p>City: {address.city}</p> <p>State: {address.state}</p> <p>Country: {address.country}</p> </div> ); } export default App; ``` # Author This usegeoaddress hook was developed by therohantomar. For any inquiries or feedback, please contact me at therohantomar@gmail.com. Feel free to customize the readme file further based on your specific requirements or additional information you'd like to provide. Member The author's name should be mentioned as "therohantomar" and the email address as "therohantomar@gmail.com".