This project is a dynamic and interactive web application designed to provide users with a fresh perspective and daily inspiration by fetching and displaying random quotes from an external API. Built using the powerful combination of React.js for the frontend and Axios for handling HTTP requests, this application serves as an excellent, practical example of modern frontend development practices and robust API integration.
- Daily Random Quotes: On page load or upon user interaction (e.g., clicking a button), the application fetches a new, unique piece of advice.
- Modern Frontend Stack: Utilizes React.js (functional components and hooks) for a fast, component-based, and maintainable user interface.
- Efficient Data Fetching: Implements Axios as the promise-based HTTP client, leveraging its features like automatic JSON transformation and a streamlined API for making requests to the advice service.
- Interactive UI: A clean, intuitive design makes it easy for the user to quickly get new advice.
- Responsive Design: Ensures a seamless experience across various devices and screen sizes.
- Frontend Framework: React
- HTTP Client: Axios
- Styling: CSS3
- External API: Advice Slip JSON API
To get a copy of this project up and running on your local machine, follow these steps:
Make sure you have Node.js and npm (Node Package Manager) installed.
-
Clone the repository:
git clone [https://github.com/raymondoyondi/Advice-Generator.git](https://github.com/raymondoyondi/Advice-Generator.git) cd advice-generator -
Install dependencies: This command will install all the necessary packages, including
react,react-dom, andaxios.npm install
or
yarn install
-
Start the development server: This will compile the project and open it in your default web browser (usually at
http://localhost:3000).npm start
or
yarn start
The core logic for this application is straightforward and centered around fetching data with a React component.
src/App.jsorsrc/components/AdviceCard.js: Contains the main logic for the component, including the state management for the current advice and theuseEffecthook that handles the initial data fetch and subsequent fetches.
- The component mounts, and the
useEffecthook triggers. - An asynchronous GET request is made using Axios to the external API endpoint.
- The promise resolves, and the advice text is extracted from the response data.
- The React state is updated with the new advice, which automatically triggers a re-render of the component, displaying the new quote to the user.
Contributions are always welcome! If you have suggestions for improving the code, adding new features, or fixing bugs, please feel free to:
- Fork the repository.
- Create a new feature branch (
git checkout -b feature/AmazingFeature). - Commit your changes (
git commit -m 'Add some AmazingFeature'). - Push to the branch (
git push origin feature/AmazingFeature). - Open a Pull Request.
This project is licensed under the MIT License. See the LICENSE file for more details.