Recipe Finder using ReactJS
Last Updated :
23 Jul, 2025
In this project article, we will be creating a recipe finder application using the React library. We have given the application the name "GeeksforGeeks Recipe Finder". This application is completely developed in ReactJS and mainly focuses on the functional components and also manages the various states of the application.
This application allows users to search for a wide range of recipes for different dishes. There are default recipes displayed to the user when the user visits the application for the first time. All the logic of recipe research, getting the results, and displaying them in the card format is implemented using JSX.
Preview Image
Prerequisites and Technologies
Approach:
For creating the Recipe Finder application using ReactJS, we have developed a search bar in which the user can input the dish name for which he or she needs the recipe. Once the user enters the dish name, the recipes are fetched from an Edamam API. This contains a large set of food databases, along with the dishes and their recipes. So according to the user's search, the matching dishes and their recipes are shown to the user in the form of card elements. We are using Tailwind CSS for styling the UI components of the application.
Project Structure:
Project Structure | Recipe Finder using ReactJSSteps to create the application
Step 1: Set up the React project using the below command in VSCode IDE.
npm create vite@latest recipe-app --template react
Step 2: Navigate to the newly created project folder by executing the below command.
cd recipe-app
Step 3: As we are using Tailwind CSS for styling, we need to install it using the npm manager. So execute the below command in the terminal, to install the tailwind CSS.
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init
The updated dependencies in package.json will look like this:
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0",
"vite": "^4.0.0"
},
"devDependencies": {
"tailwindcss": "^3.3.3",
"postcss": "^8.4.0",
"autoprefixer": "^10.4.0"
}
Step 4: After executing the above command, a 'tailwind.config.js' will be generated, so paste the below content in this file for the correct configuration.
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
"./index.html",
"./src/**/*.{js,jsx,ts,tsx}",
],
theme: {
extend: {},
},
plugins: [],
}
Step 5: Now, in the src directory create a file as RecipeCard.jsx, which will consist of the code for presenting the recipes to the user.
Example: Insert the below code in the App.js and RecipeCard.jsx file mentioned in the above directory structure.
CSS
/* index.css */
@tailwind base;
@tailwind components;
@tailwind utilities;
JavaScript
// App.js
import React, { useEffect, useState } from 'react';
import RecipeCard from './RecipeCard';
const App = () => {
const APP_ID = 'YOUR_API_ID';
const APP_KEY = 'YOUR_API_KEY';
const [food_recipes, setfood_recipes] = useState([]);
const [search_recipe, setSearch_recipe] = useState('');
const [search_query, setSearch_Query] = useState('chicken');
useEffect(() => {
getRecipesFunction();
}, [search_query]);
const getRecipesFunction = async () => {
const response = await fetch(
`https://api.edamam.com/search?q=$%7Bsearch_query%7D&app_id=$%7BAPP_ID%7D&app_key=$%7BAPP_KEY%7D%60
);
const data = await response.json();
setfood_recipes(data.hits);
};
const updateSearchFunction = (e) => {
setSearch_recipe(e.target.value);
};
const getSearchFunction = (e) => {
e.preventDefault();
setSearch_Query(search_recipe);
setSearch_recipe('');
};
return (
<div className="bg-blue-50 min-h-screen font-sans">
<header className="bg-blue-500 py-4 text-white">
<div className="container mx-auto text-center">
<h1 className="text-3xl sm:text-4xl
md:text-5xl lg:text-6xl
font-extrabold tracking-tight">
<span className="block">GeeksforGeeks
Recipe Finder</span>
</h1>
</div>
</header>
<div className="container mx-auto mt-8 p-4
sm:px-6 lg:px-8">
<form
onSubmit={getSearchFunction}
className="bg-white p-4 sm:p-6
lg:p-8 rounded-lg shadow-md
flex flex-col sm:flex-row items-center
justify-center space-y-4 sm:space-y-0
sm:space-x-4"
>
<div className="relative justify-center flex-grow
w-full sm:w-1/2">
<input
type="text"
name="search"
value={search_recipe}
onChange={updateSearchFunction}
placeholder="Search for recipes..."
className="w-full py-3 px-4 bg-gray-100
border border-blue-300 focus:ring-blue-500
focus:border-blue-500 rounded-full
text-gray-700 outline-none transition-colors
duration-200 ease-in-out focus:ring-2
focus:ring-blue-900 focus:bg-transparent
focus:shadow-md"
/>
</div>
<button
type="submit"
className="bg-blue-500 hover:bg-blue-600 focus:ring-2
focus:ring-blue-900 text-white font-semibold py-3 px-6
rounded-full transform hover:scale-105 transition-transform
focus:outline-none focus:ring-offset-2
focus:ring-offset-blue-700"
>
Search Recipe
</button>
</form>
</div>
<div className="container mx-auto mt-8 p-4 sm:px-6 lg:px-8">
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3
lg:grid-cols-4 gap-4">
{food_recipes.map((recipe) => (
<RecipeCard key={recipe.recipe.label} recipe={recipe.recipe} />
))}
</div>
</div>
</div>
);
};
export default App;
JavaScript
// RecipeCard.jsx
import React from 'react';
const RecipeCard = ({ recipe }) => {
return (
<div className="bg-white shadow-lg rounded-lg
overflow-hidden hover:shadow-xl
transition-transform hover:scale-105">
<div className="relative">
<img
className="w-full h-48 object-cover
object-center rounded-t-lg"
src={recipe.image}
alt={recipe.label}
/>
<div className="absolute top-2 left-2 bg-indigo-500
text-white py-1 px-2 rounded">
{recipe.dishType[0]}
</div>
</div>
<div className="p-4">
<h1 className="text-2xl font-semibold text-gray-800
mb-2 capitalize">
{recipe.label}
</h1>
<div className="text-gray-600 mb-4">
<span className="block mb-1">
<b>Ingredients:</b>
</span>
{recipe.ingredientLines.map((ingredient, index) => (
<span key={index} className="block pl-4">
{ingredient}
</span>
))}
</div>
<div className="flex items-center justify-between">
<a
href={"/"}
target="_blank"
rel="noopener noreferrer"
className="text-indigo-500 font-semibold
hover:underline"
>
View Recipe
</a>
<div className="flex items-center text-gray-600">
<span className="flex items-center mr-4">
<svg
xmlns="https://www.w3.org/2000/svg"
className="h-4 w-4 mr-1"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
d="M12 5v14m0 0V5m0
0v14m0-14h14m-14 0H5"
/>
</svg>
1.2K
</span>
<span className="flex items-center">
<svg
xmlns="https://www.w3.org/2000/svg"
className="h-4 w-4 mr-1"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
d="M6 18L18 6M6 6l12 12"
/>
</svg>
6
</span>
</div>
</div>
</div>
</div>
);
};
export default RecipeCard;
Steps to run the application:
Step 1: Run the application by executing the following command in the terminal.
npm run dev
Step 2: Open a web browser like Chrome or Firefox and type the following URL in the address bar.
http://localhost:5173/
Step 3: Change API Key and API Code in your App.js
const APP_ID = 'YOUR_API_ID';
const APP_KEY = 'YOUR_API_KEY';
Output:
Recipe Finder using ReactJS
Similar Reads
React Tutorial React is a powerful JavaScript library for building fast, scalable front-end applications. Created by Facebook, it's known for its component-based structure, single-page applications (SPAs), and virtual DOM,enabling efficient UI updates and a seamless user experience.Note: The latest stable version
7 min read
React Fundamentals
React IntroductionReactJS is a component-based JavaScript library used to build dynamic and interactive user interfaces. It simplifies the creation of single-page applications (SPAs) with a focus on performance and maintainability.React.jsWhy Use React?Before React, web development faced issues like slow DOM updates
7 min read
React Environment SetupTo run any React application, we need to first setup a ReactJS Development Environment. In this article, we will show you a step-by-step guide to installing and configuring a working React development environment.Pre-requisite:We must have Nodejs installed on our PC. So, the very first step will be
3 min read
React JS ReactDOMReactDOM is a core React package that provides methods to interact with the Document Object Model, or DOM. This package allows developers to access and modify the DOM. It is a package in React that provides DOM-specific methods that can be used at the top level of a web app to enable an efficient wa
3 min read
React JSXJSX stands for JavaScript XML, and it is a special syntax used in React to simplify building user interfaces. JSX allows you to write HTML-like code directly inside JavaScript, enabling you to create UI components more efficiently. Although JSX looks like regular HTML, itâs actually a syntax extensi
5 min read
ReactJS Rendering ElementsIn this article we will learn about rendering elements in ReactJS, updating the rendered elements and will also discuss about how efficiently the elements are rendered.What are React Elements?React elements are the smallest building blocks of a React application. They are different from DOM elements
3 min read
React ListsReact Lists are used to display a collection of similar data items like an array of objects and menu items. It allows us to dynamically render the array elements and display repetitive data.Rendering List in ReactTo render a list in React, we will use the JavaScript array map() function. We will ite
5 min read
React FormsForms are an essential part of any application used for collecting user data, processing payments, or handling authentication. React Forms are the components used to collect and manage the user inputs. These components include the input elements like text field, check box, date input, dropdowns etc.
5 min read
ReactJS KeysA key serves as a unique identifier in React, helping to track which items in a list have changed, been updated, or removed. It is particularly useful when dynamically creating components or when users modify the list. In this article, we'll explore ReactJS keys, understand their importance, how the
5 min read
Components in React
React ComponentsIn React, React components are independent, reusable building blocks in a React application that define what gets displayed on the UI. They accept inputs called props and return React elements describing the UI.In this article, we will explore the basics of React components, props, state, and render
4 min read
ReactJS Functional ComponentsIn ReactJS, functional components are a core part of building user interfaces. They are simple, lightweight, and powerful tools for rendering UI and handling logic. Functional components can accept props as input and return JSX that describes what the component should render.What are Reactjs Functio
5 min read
React Class ComponentsClass components are ES6 classes that extend React.Component. They allow state management and lifecycle methods for complex UI logic.Used for stateful components before Hooks.Support lifecycle methods for mounting, updating, and unmounting.The render() method in React class components returns JSX el
4 min read
ReactJS Pure ComponentsReactJS Pure Components are similar to regular class components but with a key optimization. They skip re-renders when the props and state remain the same. While class components are still supported in React, it's generally recommended to use functional components with hooks in new code for better p
4 min read
ReactJS Container and Presentational Pattern in ComponentsIn this article we will categorise the react components in two types depending on the pattern in which they are written in application and will learn briefly about these two categories. We will also discuss about alternatives to this pattern. Presentational and Container ComponentsThe type of compon
2 min read
ReactJS PropTypesIn ReactJS PropTypes are the property that is mainly shared between the parent components to the child components. It is used to solve the type validation problem. Since in the latest version of the React 19, PropeTypes has been removed. What is ReactJS PropTypes?PropTypes is a tool in React that he
5 min read
React Lifecycle In React, the lifecycle refers to the various stages a component goes through. These stages allow developers to run specific code at key moments, such as when the component is created, updated, or removed. By understanding the React lifecycle, you can better manage resources, side effects, and perfo
7 min read
React Hooks
Routing in React
Advanced React Concepts
React Projects