New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

foodie-react

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

foodie-react

A package to offer a built-in component for searching and viewing restaurants nearby in your React App.

  • 1.0.14
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

foodie-react v1.0.14

Foodie React Main

This is the source code for the upcoming foodie-react NPM package: a package that React developers can use to insert an instant restaurant search pane in their app.

A few years ago, I was working with someone who said, "I want you to be able to order Pizza from our app". That encouraged me to come up with foodie, the command line interface one can use to find restarants nearby.

Here we are years later, and I am inspired to bring that logic into a genuine user interface. No matter what your React app does, with foodie-react, your React app will definitely be able to order pizza-or any cuisine for that matter!

Installation

// using NPM
npm install foodie-react

// using yarn
yarn add foodie-react

Usage

import "./App.css";
import FoodieReact from "foodie-react";

function App() {
  return (
    <div className="App">
      <h1>SOME REACT APP</h1>
      <p>TESTING App.js in Example project (which imports my NPM library)</p>
      <FoodieReact
        GMapsApiKey={process.env.REACT_APP_GOOGLE_MAPS_API_KEY}
        devPort={process.env.REACT_APP_PORT}
        radius={5000}
      />
    </div>
  );
}

export default App;

Props

PropTypeRequiredDefaultDescription
GMapsApiKeystringYes-Your Google Maps API key. Required for geocoding and places API functionality. Get an API key
devPortnumberNo8080Port number for development server
radiusnumberNo10000Search radius in meters for nearby restaurants
searchstringNoundefinedText search for nearby restaurants

The FoodieReact component will automatically start searching for restaurants when the component is mounted. The component will appear as a floating button in the middle-left of the screen. You click it to open the list of restaurants.

Foodie React List

Once the list is open, you can search more specifically by typing in the search bar and clicking the "Find Food" button. You can also click on individual restaurants to get more information about them.

Foodie React Restaurant

The Local Server

The server.js file is a simple Express server that serves as a proxy for the Google Maps API. It is used to fetch data from the Google Maps API and return it to the client so that you can get around the CORS issue. It is not required for the foodie-react package to work, but it is required for your project to work locally-unless you have a different proxy setup.

Below is an example of a server.js file that you can use to get around the CORS issue.

require("dotenv").config();
const express = require("express");
const axios = require("axios");
const cors = require("cors");

const app = express();
const port = process.env.REACT_APP_PORT;

// Use CORS middleware
app.use(cors());

app.get("/foodie/getAll", async (req, res) => {
  const { latitude, longitude, keyword, radius, key } = req.query;
  const url = `https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=${latitude},${longitude}&radius=${radius}&type=restaurant&keyword=${encodeURIComponent(
    keyword
  )}&key=${key}`;
  try {
    const response = await axios.get(url);
    res.json(response.data);
  } catch (error) {
    console.error(error);
    res.status(500).send("Error fetching data from Google Maps API");
  }
});

app.get("/foodie/getRestaurant", async (req, res) => {
  const { placeid, key } = req.query;
  const url = `https://maps.googleapis.com/maps/api/place/details/json?placeid=${placeid}&key=${key}`;
  try {
    const response = await axios.get(url);
    res.json(response.data);
  } catch (error) {
    console.error(error);
    res.status(500).send("Error fetching data from Google Maps API");
  }
});

app.listen(port, () => {
  console.log(`Server running at http://localhost:${port}`);
});

Once you have this server set up, all you need to do is provide a port to be used. If no port is provided then 8080 will be used by default. If you have this set up, then FoodieReact will work out of the box and before running npm start you will need to run node server.js to start the server.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Keywords

FAQs

Package last updated on 16 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc