This project is a simple shopping cart application built using React. The application allows users to view, add, update, and delete products. It employs mock APIs to fetch and manage data, utilizing axios
for HTTP requests. The project also features page navigation implemented with react-router-dom
.
- View Products: Users can view a list of available products.
- Add Products: Users can add new products to the list.
- Update Products: Users can edit the details of existing products.
- Delete Products: Users can remove products from the list.
- Navigation: Users can navigate between different pages of the application.
- React: For building the user interface.
- CSS: For styling the components.
- HTML: For structuring the web pages.
- Axios: For making HTTP requests to the mock API.
- React Router: For handling navigation between pages.
Shopping Cart
|
|----readme.md
SOLUTION
├── public
│ └── index.html
├── src
│ ├── App.js
│ ├── components
│ │ ├── CardTotal.jsx
│ │ ├── Navbar.jsx
│ │ ├── ProductCard.jsx
│ │ └── ProductForm.jsx
│ ├── index.css
│ ├── index.js
│ └── pages
│ ├── About.jsx
│ ├── Main.jsx
│ ├── NewProduct.jsx
│ ├── ProductList.jsx
│ └── UpdateProduct.jsx
├── package.json
└── yarn.lock
- public/index.html: The main HTML file that serves the React application.
- src/App.js: The root component that configures routing and renders the main layout.
- src/components: Contains reusable components like
CardTotal
,Navbar
,ProductCard
, andProductForm
. - src/index.css: The main CSS file for global styles.
- src/index.js: The entry point of the React application, rendering the
App
component. - src/pages: Contains different page components like
About
,Main
,NewProduct
,ProductList
, andUpdateProduct
.
- Mock API is used to simulate server-side operations.
axios
is employed to make HTTP requests for fetching, adding, updating, and deleting product data.
useState
is used to manage the state of products and form inputs.
react-router-dom
is used for navigating between different pages (Main
,About
,NewProduct
,ProductList
, andUpdateProduct
).useNavigate
is used to programmatically navigate between pages.useLocation
is used to access the current location object, which contains information about the current URL. This is particularly useful for conditionally rendering components based on the current route or passing state between routes.
- Product List: Displays a list of products fetched from the mock API.
- Add Product: A form to add new products, updating the state and mock API.
- Update Product: A form to edit existing product details, updating the state and mock API.
- Delete Product: A feature to remove products from the list and mock API.
This project demonstrates the fundamental concepts of a CRUD (Create, Read, Update, Delete) application in React. It showcases how to use axios for API calls, useState for state management, and react-router-dom for navigation, including the use of useNavigate and useLocation. The modular structure and clear separation of components make the application easy to understand and extend.