npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

use-geo-content

v1.0.1

Published

A React hook for geolocation-based content fetching

Downloads

10

Readme

useGeoContent Hook

This custom React hook, useGeoContent, was developed for personal purposes to simplify geolocation-based content fetching in React, Vite, and Next.js projects. It leverages the browser's Geolocation API and a geocoding service to detect the user's city, country, and region, then fetches region-specific content accordingly.

Features

  • Fetch user's city, country, and region using latitude and longitude.
  • Integrate region-specific content dynamically.
  • Built-in error handling and fallback mechanisms.
  • Works seamlessly in React, Vite, and Next.js projects.

Repository

GitHub Repository: UseGeoContent


How to Use

Follow these steps to use the useGeoContent hook in your project:

1. Clone the Repository

To start using this hook, clone the repository:

# Clone the repository
$ git clone [email protected]:EliavYair1/UseGeoContent.git

# Navigate to the project directory
$ cd UseGeoContent

2. Install Dependencies

Ensure you have the required dependencies installed. If the project uses a package manager (e.g., npm or yarn), install dependencies by running:

# Install dependencies
$ npm install

3. Import the Hook

Copy the useGeoContent.js file from the repository into your project, or include it as a module in your project setup. Then import it into your component:

import useGeoContent from "./hooks/useGeoContent";

4. Configure the Hook

Use the hook in your React components by providing the necessary options:

function App() {
  const fetchContent = async (region) => {
    const contentMap = {
      US: "Hello from the United States!",
      CA: "Bonjour du Canada!",
      UK: "Greetings from the United Kingdom!",
    };
    return contentMap[region] || "Hello from somewhere in the world!";
  };

  const { region, city, country, content, loading, error } = useGeoContent({
    defaultRegion: "US",
    fetchContent,
  });

  if (loading) return <div>Loading...</div>;
  if (error) return <div>Error: {error.message}</div>;

  return (
    <div>
      <h1>Geo-Specific Content</h1>
      <p>Region: {region}</p>
      <p>City: {city || "Unknown City"}</p>
      <p>Country: {country || "Unknown Country"}</p>
      <p>Content: {content}</p>
    </div>
  );
}

5. Run Your Application

Run your project locally to test the hook:

# For React projects
$ npm start

# For Vite projects
$ npm run dev

# For Next.js projects
$ npm run dev

6. Customize as Needed

Feel free to modify the hook or add features to suit your specific needs. For instance, you can integrate a different geolocation API service or enhance error handling.


Contributing

This project was developed for personal use, but contributions are welcome! If you'd like to improve the hook or add features, feel free to submit a pull request.

  1. Fork the repository.
  2. Create a new branch for your feature or bugfix:
    git checkout -b feature-name
  3. Commit your changes:
    git commit -m "Add feature-name"
  4. Push to your fork:
    git push origin feature-name
  5. Open a pull request on the original repository.

License

This project is licensed under the MIT License. You are free to use, modify, and distribute this hook as long as proper attribution is provided.


Happy coding! Feel free to reach out if you encounter any issues or have suggestions for improvements.