The random Gif Generator is a React-based web app style with Tailwind CSS. Users can generate GIFs with a single click, or search by tags, providing an engaging experience with dynamic content.
TITLE:
The "Random GIF Generator is a web application built using React, a popular JavaScript library for building user interfaces framework and styled with Tailwind CSS, a utility-first CSS framework.
The project allows users to generate random GIFs or search for GIFs based on specific tag. It utilizes the GIPHY API to fetch and display GIFs in real-time.
TECHNOLOGY USED:
1. HTML: The standard markup language used for structuring content on the web.
2. JavaScript: A versatile programming language that adds interactivity and dynamic behaviour to web applications, JavaScript is used to handle user interactions, API requests, and state management.
3. React: A JavaScript library for building user interfaces. It allows for the efficient rendering of components and state management.
4. Axios: A popular JavaScript library for making HTTP requests. Used for fetching GIFs from the GIPHY API.
5. Tailwind CSS: Autitiliy-first CSS framework that simplifies styling by applying classes. It enhances development speed and maintains consistent styling.
6. GIPHY API: An API that provides access to a vast collection of GIFs. Used to fetch random GIFs or tags-based GIFS for the project.
STEPS:
1. Install Dependencies: The project uses React, Axios for making API requests, and Tailwind CSS for styling. To set up the project, install the necessary dependencies using npm.
2. API Key Setup: Replace the `REACT_APP_GIPHY_API_KEY` placeholder in the code with your own GIPHY API key.
3. Components Breakdown:
'Random' Component: Displays a random GIF when the "Generate" button is clicked. Utilizes the 'useGif' customer hook to fetch GIFs.
'Tag' Components: Allows users to input a tag and generate a random GIf based on the specified tag. Also uses the 'useGif hook for fetching GIFs.
'useGif' Custom Hook: Handle the fetching of GIFs from the GIPHY API. It takes an optional tag parameter for tag-based searching.
'Spinner' Components: Renders a loading spinner while GIFs are being fetched.
4. Application Entry Point ('App.js'): Combines the 'Random' and 'Tag' components, creating the main user interface. It's wrapped in a 'React.StrictMode' to catch potential issues during development.
5. Styling with Tailwind CSS: The project is styled using Tailwind CSS, a utility-first CSS framework that enables rapid and efficient styling without writing custom CSS. The 'tailwind.cinfig.js' file is used to configure Tailwind CSS.
6. API Fetching ('useGif' Hook): The 'useGif' hook handles fetching GIFs from the Axios library to make GET requests to the GIPHY API and updates the GIF and loading state accordingly.
STEPS OF API FETCH:
1. Inside the 'useGif' custom hook the 'fetchData' function is defined. It takes an optional 'tag' parameter.
2. The 'fetchdata' function sets the loading state to 'true' to display the spinner while fetching GIF data.
3. Using Axios, a GET request is made to the GIPHY API. If a tag is provided, the URL is constructed with the tag parameter for-based GIF fetching.
4. Upon receiving a response, the URL of the downsized large image is extracted from the data.
5. The GIF state is updated with fetched image URL, and the loading state is set to 'false' to display the fetched GIF.
6. The 'useEffect' hook in the 'useGif' custom hook initializes the data fetching when the component mounts. A default tag of 'Guitar' is used to fetch a random GIF initially.
CONCLUSION:
The "Random GIF Generator" project demonstrates the use of React, Axios, and Tailwind CSS to create a user-friendly web application that fetches and displays GIFs from the GIPHY API. Users can generate random GIFs or search for GIFs based on tags. The project's modular structure and the use of custom hooks enhance code readability and maintainability. The integration of Tailwind CSS streamlines styling. and the use of API requests showcases real-time data retrieval.
Submitted by Priyanka Chauhan (Piku)
Download packets of source code on Coders Packet
Comments