From d7989656f0042cbf74e8de1e9fbd95b8c0841131 Mon Sep 17 00:00:00 2001
From: zohair <Zohair.ul.hasan@gmail.com>
Date: Sat, 6 Nov 2021 21:52:51 -0400
Subject: [PATCH] fixed minor bug where when user starts typing, the website
displays no ingredients found when it's actually loading the suggested
ingredients
---
src/pages/home/components/SearchBar.js | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/src/pages/home/components/SearchBar.js b/src/pages/home/components/SearchBar.js
index 0554cf9..5607ae8 100644
--- a/src/pages/home/components/SearchBar.js
+++ b/src/pages/home/components/SearchBar.js
@@ -2,17 +2,15 @@ import React, { useState } from 'react'
import TextField from '@mui/material/TextField';
import { Stack } from '@mui/material';
import Autocomplete from '@mui/material/Autocomplete';
+var axios = require("axios").default;
function SearchBar(props) {
const [suggestions, setSuggestions] = useState([])
- const [items, setItems] = useState("")
-
+ let items = [];
const handleChange = (event) => {
- setItems(event.target.value)
- var axios = require("axios").default;
-
+ items = event.target.value;
var options = {
method: 'GET',
url: 'https://spoonacular-recipe-food-nutrition-v1.p.rapidapi.com/food/ingredients/autocomplete',
@@ -22,16 +20,14 @@ function SearchBar(props) {
'x-rapidapi-key': '9488865383msh30a38be9ec16e99p109d9bjsn9090d29ce12f'
}
};
-
+
axios.request(options).then(function (response) {
setSuggestions(response.data.map(result => result.name))
}).catch(function (error) {
console.error(error);
});
-
}
-
const handleSubmit = (event, value) => {
event.preventDefault()
if (value) {
--
GitLab