- Podcasts
- ReactJS Developers Podcast
- Build an E-Commerce Website with React JS | Practical React Project
Build an E-Commerce Website with React JS | Practical React Project
ReactJS Developers Podcast
- December 3, 2026
- 1 h 16 min
- Episode 26
About this episodeReady to take your React JS skills beyond the basics? In this episode, we explore the development of an E-Commerce project using React JS…
- How to structure an E-Commerce project in React JS.
- Creating reusable React components.
- Displaying products dynamically.
- Managing product information and application state.
- Implementing product selection and shopping cart functionality.
- Handling user interactions and events.
- Using React Hooks to manage component behaviour.
- Organising application pages and components.
- Building a responsive shopping interface.
- Applying React concepts to a practical real-world project.
- React JS beginners ready for practical projects.
- Frontend developers building their portfolios.
- JavaScript developers transitioning to React.
- Students interested in E-Commerce application development.
- Developers who want to strengthen their React project-building skills.
Transcript
From the publisherThis transcript comes from the podcast’s own feed, shown as the publisher wrote it.
Build an E-Commerce Website with React JS | Practical React Project
In this lecture, I have shared a small project with you, which will be teaching you a lot of things, especially our previous lecture, React, Rotter, DOM. That is going to be implemented here. And along with that, how to handle Fetch, Axios, API, etc. You must be getting all those ideas here. So, what you are seeing on the screen is our small project. You will say that there is nothing here. What is written here? Self-work, styling is to be done. So, this is the home page basically. I have left the home page for you. The way you have to style an e-commerce home page, you can do it. I have not focused too much on styling. Here you have the main product page. Here, as soon as you click on the product page, your data will be loaded. It may take some time to fetch. It may take 200-300 milliseconds. It may take 1 second. So it takes time to fetch the data. As long as the data is fetching, the loader will be visible. And as soon as the data is fetched, you will have the entire data listed. Now, this is not all, the special thing is that the routing is done, all dynamic routing, or whatever I told you in the last lecture, you will see that the concept is being used, and we have used the latest create browser router approach, so here I want you to see this TV, not a TV, sorry, it is a monitor, Clicking on the monitor should open a detailed page related to this. We are not doing props drilling here. We are not doing props drilling here. We are not doing props drilling here. We are not doing props drilling here. We are not doing props drilling here. We are not doing props drilling here. We are not doing props drilling here. As soon as the data is fetched, you will see all the details related to it. As you can see the image here, you can see the full title here. If you look at the product page, then you can see the dot dot dot dot here. The whole title is not visible, the description is also not visible, only the rating, count and price are visible here. As soon as I clicked on it, the whole detail will be fetched here related to the product, related to that single product. And here you can see the monitor, image etc. And here you can see the whole title, price etc. And you can also see the description. And if there was more data related to this, then I could have shown more here. But we have used the API. Made-up API. So, it was a little limited there. So, we have shown only this much. And, there were many more things in this API. If you talk about fake story API, then here is cart too. You can add product, remove product, delete product. But, proper state management will also be involved there. And, we have not done state management in that much depth. State management does not mean that you have done only use state. It is not that much. There is prop drilling, etc. You must have heard the name. I have told you. So, we get stuck in all those things. And, we will see in the next lecture. and after that we will discuss about context, API, Redux, Toolkit etc. So now this small project is just for your practice. You don't have to think that this is a very big project. The project has not come yet. I am just making you practice this small thing. So here you have this product page. Routing is happening from home to product. We have come to the product page and we are clicking on any item. As I clicked on this, then you are getting related data here. And along with loading, This is also important to learn, how to show loading, how to show loading while data is fetching. And after data fetching, your data should be shown. Optional chaining etc. is discussed here. So you will get very interesting things to learn here. So let's make a project quickly and you will know what it is. And you will see, I will explain a little more, which I have studied in the first lecture and you have studied. Increase the speed to 2x or 1.5x but do the code by yourself. It will be fun to make this project by yourself. So let's go quickly to make the project. Come on. So first of all, we have to install Vite and Tailwind CSS as always. And for this, I have opened my folder, the React one, where I am organizing all the code properly. And you will also find it on GitHub. But the better thing is that you make your own folder and organize the folder structure properly and write the code properly. So it will be more fun. You will get a better feeling. And so many things have happened to us. You have already known that the projects we are going to do now are going to be on Fetch and Axios and React Router DOM. So if you are getting all these things, then you will easily do the setup. So let's start, it will be fun. So here you have to open the terminal first and you should also have the command to paste the command. I have not kept it, although I remember that many things, but still you have to come here on Tailwind CSS. If you want, you can go to the wheat site and install wheat first, then come to tailwind and install tailwind. But it is better that here you have proper installation of wheat and tailwind. If you want to use other framework guides, then you can also do that. We have to do wheat now, so we will do wheat and quickly copy the command here to install wheat and paste it here. Okay, here it will install us and will come inside that folder from CD my project. The name of the folder is my project. If you want to change, then do it, I don't have to do it. so here we will select react and variant we will select javascript we don't want experimental we don't want to start yet because for now we have to install tailwind so here we will copy it and paste it here keep in mind that it is inside my project otherwise if you do it in react folder then everything will be installed outside my project so inside my project you have to install everything including tailwind css All right, so this is our install. Until then, let's do more work. We have a lot of work. So copy this line here and it is saying that in my project, come to vid.config.js and paste it here. Basically, import it and put this plugin here. As he said, I did it as always. Extra kuch dimang nahi laga hai. Thik hai. To ye hamara ho gaya. Uske baad ye kera hai ki css mein jaake ye import kar lo. To main jo global css file hai. Index.css yaha pe kar luga. Halake app.css sorry css mein bhi karoge to kaam karega apka. But ye saari jai apko pata hai kaha ki is tarike se kya link hota hai. Hai na? To ye clear kar lete hai and npm run dev se run bhi kar lete hai. Kew? Hai na? To yaha pe ye hamme dikh bhi raha hoga. Is tarike se. Aur fatafat check kar lete hai ki hamara proper tarike se tailwind css is not running properly, we can hide it, let's hide it, let's zoom it a little, let's clear the garbage here, this is the garbage, because we don't need it, we don't need it, it means it is garbage for now, so remove it, now don't link it from the other place, so here what to do, we have to check the simple palette, tailwind is not working, hello g, how are you, class name and I will use bg-red500 here. If you are not getting suggestions, then reload once. You will get the suggestion. Although you get it, but sometimes it gets stuck like this. So reload and you will get the suggestion. Rest, this is working. Look, hello. And it is coming in the middle because by default some CSS is given. So this will create a little problem for us. So do one thing. Remove all these CSS from index.css. Or If you don't want to remove it, some things will work, like this button, etc. H1 and all these things, something will work. So let's do one thing, just this little root one, let it be too. There is no need to remove anything, just remove this body. If you remove this body from here, then this will come up and still some margin padding is visible, it is in app.css, see this. This root given, hashtag root, hashtag root, so remove this from here and this is now doing your proper work. And one thing that I want to check here, whether our height is working or not. So it won't be working because the height of the parent container is nothing. Who is its parent? Parent is your root, HTML, body. So until it doesn't have height 100%, until you give it height 100%, it won't work, right? So come to index.css here. And this root, not like this, something like this. Here, html, body, and hashtag root. Why hashtag? Because our root index is id. You can go and see in html. So we have selected the root and we will give its width 100%. And we will give the height 100%. So now if we here app.jsx or anywhere, if parent has height full, then we will give its height full too. So it will work. Height full means 100%. So it is working. But now it doesn't need it. I just checked if it is working or not. So it is working. It is working properly. Alright. So what do we have to do now? First of all, we will make a number. And if you want, you can set up a reactor router DOM first. We will do that too. But first of all, let's make some components. Right? Components and small and cute components are going to happen. Two, three, four components are going to happen, not more than that. So I just make a component folder. I will also make pages and components in it. No problem. No problem. If you want, you can make a separate page folder. You can make a separate homepage, product page and component. But not that much. This is our small project. So we will create a new file here. And navbar.jsx rafc. Okay. Then one will come here. Our homepage. Home.jsx rafc. And we will get another one. Product page. P-R-O-D-U-C-T-S. Products. Not products. Products.jsx rafc. This is our products. Close app.css. product page products products.jsx r-a-f-c products app.css close and work on navbar remove all these things don't do much in navbar make a nice navbar which we will make we are very expert in styling I don't know you are expert in styling I can't do much in style etc So I will not do much style, I will do a little style and our work will be done. So this is our fragment, let's make it and here let's make a div in which we will use a link. We have not installed the link yet, so let's install the react-router-dom. Split the terminal here, npm i react-router-dom, you know all this, enter it. spell it correctly install it quickly kill it don't kill the server don't kill the react app hide it and if you kill it then run it again so here it is div we will use link in it and where will this link come from it didn't import so import link from react router dom There is nothing new for you. You have read everything. So link. One will be home. And one will be with us. Product. Alright. Home and product. Why is it not visible? Okay. How will it be visible? It will be visible when we will put a navbar here. It will be visible when we will put a navbar here. So let's put a navbar here. Now if we will put a navbar, you will get an error. You will get an error, right? You will not get it? Look, you will get an error. You will definitely get it. Why will you get it? Quickly tell me why you are getting this error. If you have told me why you are getting this error, that means you have seen the video of React Router DOM properly. You have proper crystal clear understanding. If you have seen it, then you will have crystal clear understanding. I know this. And if you haven't seen it, then you may not be able to understand what the error is. So let me tell you, here we have used this link in the navbar. Use the link now, or use the navlink, or use the navigate. To use all these things, you have to properly set up the router provider here. Use the old syntax, the browser router, you can wrap it in that. Or whatever routes you make in the create browser router, you can use link, navlink in that. You can't use it like this. You can use the elements in the RouterProvider. So, do we have to make it first? Yes, you have to make it. If you want to use the link without page reload, you want to navigate, you want to create routes, then you have to make it. So, let's make it. Shall we make it in app.jsx? So, in app.jsx, I had made it in react-router-dom too. By making app.jsx and layout.jsx. This time, let's make it in main.jsx. If you do it in different ways, then it will be fun and the understanding will increase. Right? So now the purpose is to learn, the rest is to see how to do the proper production approach. So now the main purpose is to learn. So let's do it in main.jsx, your practice will also be done. First you do it yourself. The latest syntax I told you about the create browser router, you first implement it yourself, then see. Rest I am starting here. So let's remove strict mode, there is no need. I removed strict mode. here we will import create browser router and it is imported and here we will create different routes using create browser router it is an array of objects that means there are multiple objects in one array one object is one route, second object is second route, third object is third route so you have to create as many routes as you want do you agree with this? yes I agree so how will we do it? so here you have to tell the path what will be the path? why we are not getting the suggestion? If the path here is slash, then which element do you want to render? So I want to render the home page here. So I can't see the home one here, so I have to import it. From dot slash component slash home. And do one thing, along with home, import products here too. Products. So here you have home. And in the same way, put a comma here. And in the same way, you will get products here. So if you are on the slash route, then you will see home. If you are on the slash products route, then you will see products. Any problem? No, there is no problem. So if you come here now, reload, there is no error yet because we have removed the navbar from here. We have just emptied the navbar from app.jsx. So now we are doing all the work in main.jsx. So if we go to slash, we will see home. And if we go to slash products, we will see products. Nothing is visible. I just told you that you have created different routes by using create browser router. But where did you use it? Where did you provide it in your application? So save it in a variable. Name it router, route, you can name it anything. And here you have to use router provider. Router provider, like this. Router provider. And where will it come from? Obviously, from react router DOM. See, it is also suggesting. So, we have got a router provider from react-router-dom. See, create-browser-router and react-router-provider both have come from react-router-dom. Alright. So, here, in router-provider, you have to pass a prop, router. So, in router, you can give any name to this router you have made. RT, router, R, you can give only R. You have to put that R here. So, I will write the full name. What is the problem? Router. So, you have to put this router here. That's it. You have provided the router. Okay. And this is your app. So for now, whatever you write in the app will be visible to you. Because along with the router, you have also installed the app here. So that will also be visible. So let's reload here. Now if you look carefully, then leave this app. This app.jsx is coming. Look at this. If you are in the products page, then the product is visible. If you go to the home page, then the home will be visible. Observe here. If you are on the slash, then the home is visible. If you go to the products page, then the products will be visible. So our router is set up. All right. Now let's talk about navbar. We were getting link and other problems in navbar. So if you use navbar here, our problem will be solved. If we use the navbar here, will the problem be solved? Not at all. I had said that whatever elements or components you are doing in the create browser router, you can only use link, navlink, useNavigate etc etc in it. Not anywhere outside. Because the react router provider is providing, but it is providing all these elements, link, navlink etc. It has nothing to do with the navbar outside. So you have to do something like this, that you have to make a parent component here, and take an outlet in it, do nesting, and then fix the navbar there. I have told you everything in detail, in a lot of detail, so much crystal clear understanding. I don't think you will get it on YouTube, you shouldn't say that, a lot of people are telling you and explaining you, but go and see once, you will get a proper understanding. I will show you how to do it now. So this is also the wrong way here, you don't have to put the navbar like this. basically you want to see the navbar in every page so for that you have a way to remove it here you want to treat app.jsx as layout which we always do so we will make app.jsx parent what will we make? we will make parent path slash element our app will come here no problem this app came so app came here so if we use navbar in app then can we use link in navbar? We can use links in navbar. First of all, the product page is not defined. Navbar is working properly. Why is it working? Because there is an app in the browser router. and your app has a navbar, then whatever you will keep in the app, your react router will be working properly with all of them. Link, navlink, useNavigate, everything will be working properly with you because you will keep all the things in the app. Okay. Now how will we make the routing? We have kept the navbar in the app, but we want something else to come with the navbar. Wait a minute. We have kept the navbar in app.jsx. Now along with the navbar, we want that something of our page will also come here. Right? So, inside the app, this app will be parent. Now, we need something inside it. So, definitely, we have to make it children. And I have told you all this. So, this will also be an array of object. So, what to do here? You give path. If you have slash path, it will be linked with it. With parent. Here you have given slash. Here also you have given slash. That means, on slash, your app will be rendered. With app, its children. This will also be rendered here. Element. Here you will have home rendered. Okay. After that, let's make another path. slash products, and here you will get the element products. So if your slash route is there, then along with the app, the home will be rendered, matching with the slash, and if the slash products are there, then the app will be rendered, along with the products page will also be rendered. But to render, you will also have to mention here that where to render, above the map bar, below, where to render, if you have not rendered anywhere, then you will not even see it. You can come to the slash products page. Can you see it or not? Because you haven't mentioned it here. These are all the children of it. Now, you have to render all these children in app.jsx. For that, you have to come to the outlet. I shouldn't have explained so much. much. But I don't know why I am explaining just for satisfaction. There was no need to explain so much. Because I have already told all these things. So this is our next outlet. So I have put outlet below navbar. That means all the children. The children routes I have made. All these will be rendered below the navbar. If I go to the home page, the navbar is fixed and the outlet is changing. Why is it changing? Because if there is a slash, then the home should be visible. If there is a slash product, then the product should be visible. Okay, did you understand that much? And if you still haven't come, then definitely you should consider that video of react router dom. So our react router is set up properly. Let's do some style. Let's keep it 100%. and this color looks a little dirty, we have given a color in the anchor tag, remove it, we don't need this useless color, however, we will apply tailwind CSS, we don't need it, so now here main.jsx, this is our app.jsx, in the app, we have to style this navbar and navbar, so we will style it, what problem will we do, we will give text to excel and here flex item center, no need to give item center here, simply give a gap of 7, see how it is looking, and here do one thing, give BG gray a little 600, so don't give 600, do one thing, here give BG gray 800, see how it looks, it is 8000, there is nothing like 1000, it is looking a little blue, It's not fun. 900. 900 is not 1000. 900. It looks like this. Do one thing. Do one thing. Give me 7. Yes, it looks good. I said a lot of style. We don't have to do that. We still have it here. So let's do as much as possible. Padding-wise. Rest, if you have extra libraries, Daisy UI and then Flow Byte, Satsian. You can make it yourself, but I'm not going to do that right now. This is not a styling lecture. We will give padding-wise of 3 here, so you will find something like this. And along with that, we give an image to put a logo here. For now, you can only give the image, people will not sit to make it on Photoshop. So here, search for store logo png. Search and come to images carefully on images and here you will get the option of tools. Go to the tools and choose transparent in color because you want transparent, you don't want color etc. Let's take this logo. So this logo is transparent, you can see some dotted checks. So let's copy the image address and come here on our project. Let's paste the image and enter the image address and our image is pasted here. Something is coming in this way, we will do one thing here. we will make div and in class name we will give its flex and item center and we will give gap of 5 so something like this is coming and we will style image a little and bg gray not here bg gray we have given in wrong place bg gray not here bg gray we have to give here and padding also we have to give here padding y3 ok main which is our parent we have to give all these things we have to not give here padding y3 and The rest is fine. This is how much we have here. If you make the image a little smaller, it will look a little cute. Let's give a class name. And in the class name, let's give a width of 20. See how it looks. So it looks like this. And it looks fine. It doesn't look very amazing. It looks fine. Let it be this much. It's better. And let's do one thing here. Let's give it a padding of 8. So see how it looks. It looks like this. And here we have not given a gap. Here we have given a gap of 5. Do one thing. Give a gap. Give 16. See how it looks. So it should look good according to me. It looks good. It looks good. And zoom is perfect. It is at 100%. Yes, it is at 100%. So good. Now click on product and home page. You should also go there. So for that we have put a link. We will not use link. We will use nav link. Because it has your You will get better features with nav link. Let's install nav link first. Here we will use nav link. Nav link and here I will say to slash and here I will say where to send it to click on products. So if we click on this, it will come to products. If we click on home, it will come to home. Now here you get a special feature in Navlink that you can track whether it is active or not. Like if we click on product, then we should see that the product one is active. Give it some color etc. So we can do that work very easily. Okay. So for that, we have to do the same work in both. Give the same class name here, give the same class name here. So we will do one thing, we will make a separate component. What is the name of this? name it menu otherwise name it link navlink or route name it will be little bit conflict with react router dom so name it menu and return and this one single navlink here return it ok and remove this also good so now what we have to do here we will receive as a prop what all we will receive first we will receive this route here right In props, we call it 2. Here we give the name of the variable 2. So we will receive 2 and call it title. So we will give 2 and title. It will be attached here. Title. You are getting all this. You have the idea of props. You are not coming here as a noob. I am assuming. So nav link. sorry not navlink but menu component and this is our one menu now we have to send two in menu which will be here so we will send two in two the first one will be slash and after that what we have to send title which will be here so in title we will give home ok so this is our proper way it will be visible here home is visible in this way replicate it and here this will be our products and here slash products So now we will do the style work with one, it will be applied in both. What we will do with one, it will be applied in both because we have made a component. So this is much better, there will be no unnecessary code length. So here we give the class name. What class name do we have to give? So we have to give a class name like this. You have to give something like this. Here basically you have to use a function in this way. And in this function, you know that you are getting a key named isActive. You will get an entire object. With that, you can remove isActive. Have you seen all this? Here isActive, if you want, you can see here. For example, you will get a parameter here. Let's say I give the name a. And here I show you a by doing CLG. What is getting in a. So here you see, a is an object. In it, you are getting isActive, isPending, isTransitioning. So if I come to the product page, then see this is active, it has become true. That means we are on the product page. Product page is active. So this is active, it has become true. So this is what we need. So we will destructure this and remove it. Is active. And what will we do here? I will say that if it is active, then do something. Otherwise do something. Okay. And if I want to put hover, then I will put hover there in CSS. Is active if it is active. If the battery is low, then give me 1 minute. If the is active, then we will give bg tomato and if the is is not active, then we will return empty string. If it is active, then this class name will be added. That means the background color will be like this. And if it is not active, then it will return empty. So if it is active, then you can see that it is active. You can see that it is active. Wow. Wow. Interesting. And you should also know about the hover. You don't know anything about the hover. So let's do one thing. Let's come here. Where? Where do we come? Oh man. We come to index.css. There is an anchor tag here. We will put hover on this anchor tag. And we will say in hover. What will we say? We will say this. color it with tomato color and take a lighter shade of tomato and this is active and you can do one more thing and if you want you can take scale of 0.9 so it will be small like this and if you put transition then it will be fun transition all Linear 0.2. So 2 seconds. I forgot this while using Tailwind. Product home, product home, product home. You must be looking great. Wow, interesting. And you can also give a little click effect on being active. I don't know why. I should not focus on the style, but it is happening. I will give it. What is the problem? We will scale it to 0.8. So we will click. So see, we clicked. So here the click effect is also known. Isn't it looking like a click effect? Wow, wow, wow. So give it 0.95 here and 0.8 here. Click effect will be more noticeable. Not more than this. Not more than this style. Not at all. So here we have this navbar. You are coming to the product page, you are coming to the home page. Home product, home product, home product. This is done. Very good. Very good. Now here, let's make a home page first. So I won't do much in home. You make a home page. Home page is your task. Make some design of your own that this is our e-commerce store. Come, visit, go to the product page. Something, something, something, make something. I simply put an H1 here. And here I will write self-work. You don't have to do much. You have to do styling here. As much styling as you can do. Styling has to be done. Styling has to be done. As good as you can make the front page, you can make it here. Basically, styling has to be done on the homepage. Self-work, styling has to be done. Alright. We will work on the product page. Any problem? There shouldn't be. Now, we will work on the product page. So, we have to work with API. with the fake store API, then for that you can search here, fake store API and here you will get the fake store API and here you come to the documentation and after coming to the documentation, product, cart, user, there are many things, we have to work on the product right now, we don't have to go to the cart user functionality right now because it will take state management etc. We will not sit here to do prop drilling. You may be knowing prop drilling. Because I have told you in the state. You will have some idea of prop drilling. And rest we will learn in the state management properly. When, where, how we are stuck in prop drilling. How to do state management. So when a big project happens. So all those things are needed. We have not done all that yet. So small, small, cute. So that you get the proper idea of react router DOM. So that you get the proper idea of XO switch. So we are going to do this much work. Okay? Okay. So, you have to come to get all products. And on get all products, you will get this get route. Click on it. And you will get the whole URL. Copy this and you can paste it here and see if you are getting the data or not. You can paste the get one on the browser and see if you are getting the data. So, how many products are there in total? You have 20 products. In ID sequence, 1, 2, 3, 4. That means you have 20 products here. Right? So, our work will be done. This one, which you have, copy this. This is our API and we will put the use effect here, use effect and call here. First of all, we will make a function const fetch data is equal to and here we have to fetch the data. Yes, we have to fetch, so we will not use fetch, we will use exios. However, you have another way. I told you in the video of react router DOM that you want to go to the product page here before the data is loaded. As you click here, first the data is loaded and then it reaches the product page. So you can also do this here. you can use the loader here and use the fetch here and then use the loader data here use the loader data hook here and take the data but we will not do it like that, the fetch data which we generally do, we will work in the same way here so in fetch data we will use axios here so let's install axios and this is our installed, it is installed, let's hide it so axios axios Suggestions are not found, mood gets spoiled a lot. Import Axios from Axios. Okay. Axios. Hmm. Now it's okay. Very good. And I hide it for now. So Axios and here you put your link. Now it will definitely fetch. But await. You have to wait. Promise will return. And if it is awaiting, then you have to make a function like this. Here you will get some response. response is equal to and here clg response you can see what response you are getting now this function will also have to be called so here we will call it in useEffect and here we will give dependency array so that it runs only once when it is reloaded so let's reload so now it is on the home page so nothing will happen we will come to the product page so see here our data is fetched we are getting an object so there is data in the object that means we are getting a response response is an object and there is data in the object And this data is the work. So response dot data. Response dot data. So now if you reload here. So see you are getting all the data. Now we will save this data in state. So make a state const data comma set data not products. Products comma set products is equal to use state. And this is our. Okay here we will set products. Instead of console we will set products. And if you want, you can see the products here by doing CLG, whether the product is being set or not. So let's reload. See, the product is being set. And by default, why did we give a string here? Give an array here, an empty array. So in the starting, see, it was an empty array. As soon as the data came, our data was set in the array. Okay, basically, you have got the data in the state. Now what you have to do is map it. So we will map it quickly and list our card. So let's do the map here. what is the problem in mapping? products.map is a higher order function, here each item will be coming and here we will return it in this way, here we will make a div and this div will be our card, very good and here in the item, you can see what is coming in the item first, so do one thing here, what is in the item, you can see from here, so you have ID, title, price, so we need the title here, In H1, you give item.title. So here you will see the title of everyone. And it should look like a card, so let's make it like a card. To make it like a card, we will give it BG. Gray 700. We will give it rounded. Large. It will be a little round. And now it will not be visible because there is no gap. So let's do one thing. We will give it Let's make it a grid. Let's make it a grid layout. Class name. Parent will call it grid. And grid column. I need 5 grids in the starting. And here we will give a gap of 4. So there will be a gap between everyone. So grid has been made. And this h1 is looking a little bigger. So here you give text excel in the class name. So it will look a little small. And actually it will not look small. Because here in index.css. I have given style in h1. So remove this style. I don't want this style. And the rest is fine. So leave it. Or if you want, remove the whole style and do all the work yourself. So it's better. I didn't think much. So it's coming in this way. Okay. And this page, our product page. What will we do in this? In this, we will give padding from all sides. 8. So it will come like this. So is 8 more? Give 6. So it looks like this. Let's reload. So now you just have the title of each of them. Now you have to show the image here too. So img and here in the image you have. What is coming in the image? In the image you have. This image is coming, isn't it? Image is your URL. Very good. So here item dot image. Okay. And here you will be getting the image. So you are getting this image, now you have to fit this image properly inside the card. So you will do that work, I know. But I will also do it and show you. Because I don't know. Right? So how will we do it? Let's see. Style etc. You have to fit this in the card. So nothing much. Give it aspect. First of all, you have to give some aspect ratio of this. give me square or video, give me square, so this whole thing will come inside the square, but it's a little chipped, I don't want it to be chipped, I want whatever image is there, its aspect ratio should be fine, it should not be chipped, it should not be too thick, it should not be chipped, the actual size should remain the same, but it should fit properly inside the card, it should not go outside the card, or it should not be cut, I want something like this, so what I will do here, object, by giving cover, it will be covered, but it will be cut a little from top to bottom, it is covered, Properly. But the one whose width is more, it is cut width wise. The one whose height is more, it is cut height wise. So I don't want to cut this. So what else do I have here? Contain is there. You give this contain. So see this. Fit has come inside the card. Properly. If you don't know, then if you give its BG red, BG red 500, then you will know. See this. If I give it a little padding, then it looks good. Give padding 4. So this little padding has come. Now it looks beautiful. Isn't it? remove this bg red from here so now it is looking like this and it is looking good and this is our image, there will be two sections in it, one will be our image and one will be our detail section, this will be our div detail section, all the details will be coming in it, like its title came, price came, so we will also do one thing, we will give padding of pipe So this is how the padding came. And in the heading, we will give a line clamp of 2. Line clamp 2 should not be more than 2 lines. If it is more than 2 lines, then dot dot dot will be applied here. Because by clicking on it, we will open another page and show all the details related to that product. We want to do something like this. So we will do it. There is no more tough task here. So this is our proper list. And it is also responsive to a great extent. Wow! Amazing! It is also responsive here. and we will make it a little more responsive. First of all, let's make a list of all the things we have to list. So this will be our title. Below this will be our price. Price. Price was the name of the key. Item dot price. Price should be. Yes, price has come here. And put rupees on the side like this. Okay. And here in class name, text to excel. And see how it looks. To excel has increased. So, do Excel and font medium. It will look a little bold. Okay. It looks like this. And in H1, do it to Excel. So, it looks like this. And what else can be done? If done, a lot can be done. And we will actually do it. Okay. We will do it. Give it a little lighter set in text white. However, the option is not coming. White divide by 40, you can also give it in gray, but why not give it in gray, do one thing here, do 70, it looks like this, and actually it is fine, we will give all the margins in it, first we will list everything, what else do you want, and this price is done, we will not show its description here, click on the description, when the full detail will open, then we will show the description there, we will not show the category here, I have shown the image. Let's show the rating. I don't think I need to show anything else. Let's show the rating. So, for rating, we will make a paragraph. And here you have item.rating. Let's see the rating first. Rating is an object and in that object, there is rate and count. So, item.rating.rate and item.rating.count. Rating.rate. And you will get item.rating.count. Ok, now you have rate and count. Alright, so here style it a little bit. Give it bg green, 6 will look good. And fit its width. It looks something like this. Give padding y of 1, padding x of 2. And make it rounded, large. It will look a little like a card. And it looks beautiful. Padding x of 4 actually. so it will look nice. Okay? It's looking good. And do one thing here. Does it get any star emoji? Star. S-T-A-R star. Wait a minute. S-T-A-R star. Yes, this one. This is our rating. It will look like a rating now. It's looking nice. And we can do one thing. It's looking a little scattered. So let's enter flex item center. So these two will be aligned together. Did it align? No, it didn't. It should have been. Flex item center. Justify center should have been. But no, it didn't. No problem. So we can do one thing to align it. I think the star is a little down. It looks like it's bent down. So I want it to be a little higher. For that, let's wrap it in a span tag. Then I don't know why I'm reading in style. Isn't it? And let's give it a class name from margin-bottom. So it will fly a little higher. Didn't pick it up. Give it a 4. Still didn't pick it up. What's the problem, my brother? What's the problem? What's the problem? Tell me. Let's wrap this in span tag too. This whole thing. Now it's fine. So I don't know if that emoji will be of this type, it is not taking it from the margin bottom. Okay, let's see the way from the padding bottom. Center is done, now make its size smaller. Make it size 2xl, see how it is looking. Make it small. And why do you have to make it small? Do one thing, make the whole small. Here it is done, make the whole text extra small, it will look better. And in extra small, there is only XS. So this is 4.7. and I want the paragraph below it to come just next to it so we have to wrap it in div and we will wrap it in div and give it flags so this is our whole rating section so rating rating rating rating and count rate and count very good this is rate and this is count So it looks good, I have to bring it in one line. So what can I do? Last name flex and I will give a gap of 4. So see how it looks. It looks like this. Give a gap of 3. It will look better. So this is done. You can do one more thing. Give it a margin of 3. So this space will come in this way. And this paragraph of yours, this price one. So put the price paragraph below this. Okay, this is looking better now. So you can see our style of this way. This is our card. And what is this error coming? So I believe the error of the key is coming. See the key is coming because we have not given a key here in div. And we will not give a key here actually because we want to make it as a card component. So cut it from here to here and make a component. Const product card. You will work by making a card, not a card, you will work by making a component, so you will be able to separate it properly at any time. So this is our card and the card is made, so here you can use the product card in this way and here you have to send details. Details is equal to here you will get the item. This item is your whole details, right? So we will also have to receive these details props here. Details. All right. And here you have to do details everywhere. There is an item here. You have to detail here too. Here too. So either detail it or leave it as an item. Item. And here too. Item. Okay. So this is done. It is still working properly. Very good. Key error is still coming. So pass the key here. Pass the ID in the key. Item dot ID. ID is unique. So this error will also run. This is done. Now let's try to make it a little responsive. So I will make it 4 after 1200px. So maximum of 1200px. Before 1200px. Means till 1200px. I want to keep grid column 4. Till 1200px. Max to max till 1200px. I want to keep grid column 4. After 1200px it will be 5. Because after 1200px I have not defined anything. So here grid column is 5. And till 1200px it is 4. And let's do one more thing. Let's make it 3 for 900 pixels. You are getting all this. Maximum of 900 pixels. Grid column 3 will be done. 13 is done. Not 13. 3 has to be done. And has this insert button been pressed? This is our 3. So now it's fine. So 900 pixels is 3. 1200 pixels is 4. After that 5 is done. And here we will make it 2 for 600 pixels. maximum of 600px grid column will be 2 and maximum of 300px grid column will be 1 not 11, 1 so see this is 2, till 300px you will have this 1 then this is 2 and then this is 3, 4 and 5 that's it And if you want, you can reduce the padding in the small screen size. Like after 600 pixels, you can reduce the padding here. Maximum of 600 pixels. After that, you give the padding of 2. You can also reduce the gap. So this is looking better now. It's looking nice. It's looking pretty. So this is done. Look carefully at the reload, it is completely blank. It is completely blank. And after being blank, this product is coming to you. It doesn't look good. It means that there is nothing on the side, there is no glitch. So here you can show a loader. You can show a loader and you can make a loader. You can make it or you can search here. Loader. Loader, loader, loader. Loader, CSS and Tailwind. So Tailwind loader, you have to simply search here. tailwind loader You will find a lot of sites like universe.io. You will find a loader somewhere. Generally, I get a loader on universe. I will copy it from here. There are many other loaders like HTML, CSS. You will find a lot of sites. You will find a lot of sites. You will find a lot of sites. You will find a lot of sites. You will find a lot of sites. You will find a lot of sites. You will find a lot of sites. you can take out any loader like you have to put this loader, which loader you have to put, you can see whichever loader you find beautiful, you can put it. So almost there, should I put this loader? This loader is also looking fine, simple. So let's do one thing, let's put this loader. So copy and let's make a loader component here. Loader component loader loader.jsx rafce And this is our style of loader. And remove this comment otherwise you will get an error. Okay, this is our loader. Properly. Very good. It was fun. It became a loader. Now we can use this loader anywhere. Okay. So I will show you by using the loader. Let's see how it looks by using the loader. First let's see how it looks. Loader. Loader. Oh man, do import from yourself. You have to import it again and again. Does it look good? You tell me, does it look good? From dot slash components dot dot slash components slash loader. I put a dot twice because after going out of the folder, there is a component and then there is a loader. Right? We are still here. So, okay, there was no need to put dot dot slash. After going out of the component, we are coming inside the component. So, where the product is, there is a loader too. So, here simply dot slash will work for you. dot slash loader. Great. So let's see how the loader looks. How is the loader looking? Oh, the loader is looking good. Okay, it's looking good. It's looking good. It's looking good. Loader is looking good. But we don't want to show the loader now. I want when the data is fetching, I want to see the loading at that time and when the data is fetched, when the data is fetched, then the loading will be false. So for now, we are not doing state management, we are not doing Redux Toolkit etc. So here we will make our state for loading. Although we make state there too, but the way of managing is a little different. For now, we do it in a simple way. So here we will make a loading state. Set loading. And here we will use useState. By default, loading will be false. Loading is false. I want the loader to be visible only when the loading is true. If the loading is true, then only the loader will be visible. Otherwise, the loader will not be visible. Return it carefully. Otherwise, the next component will also be visible. Remove the loader. Do not use it here. The loader will be visible only when the loading is true. The loader will not be visible now because the loading is not true. If I make the loading true, then the loader will be visible but not the page. I mean, the product that is coming will not be visible. Okay. So, let's do one thing. We will give a little style in the loader. Here, we receive class name. Class name as props. We receive. And here, in this way, we will attach some class name. Class name. Okay. And now, if I want here, I can give my class name. Class name. And here, we will give padding. 20. Let's see how it looks. So it looks like this. Perfect. So here you have loading and by default this loading will be false. I want loading to be true when the data is fetched. So before the data is fetched, I will set loading true here. And after the data is fetched, when the data comes and gets set in the product, then I will set loading false here. So when the data is coming, the loading will be true and the loading will be true, then the loader will be visible and when the data is running, the data will be completely fetched, then the loading will be false and the loading will be false, then the loader will not be visible and this will be completely rendered. So now if you come here and see that there is nothing to load on the home, then the data came as soon as the data came, the data was visible, the data was not there, then the loading was happening, the data came, the data was visible, wow, wow, interesting, now what to do, we have almost done our work, now all we have to do is click on it, click on it, So do we have to make different components for everyone? This is a product. In product, you also have get a single product. All the products are coming here. Get a single product. If you want the detail of a single product. So I click on this. So in single product, I just have to pass ID at last. I will give ID. I will get the details related to that. If I give 1 in ID, then I will get the detail of the first one. If I give 2 in ID, then I will get the detail of the second one. So our work will be done in single component. If ID will be 1, then I will show the data fetch of 1. If it will be 2, then I will show the data fetch of 2. It will work with single component. So for this I have to create a dynamic route. So I will create it. There is no complicated task here to create a dynamic route. It is very easy. Come to main.jsx. This will be our products. And below product we will create another route. Which we will treat as dynamic. Product slash colon id. I have given colon here, that means it has become dynamic. Now anything can come here. 1 can come, 2 can come, 3 can come, 4 can come. Whatever will come, we will receive it here in the product page. Not in the product page, let's make another page. Otherwise, it will be wrong. Let's make a single product page here. Single product.jsx. R-A-F-C. And here single product. Single product. Okay. So if I want to show you now, then I can show you here that if we go to Slash 1, then see the page of the single product is being rendered. If we go to Slash 2, then the page of the single product is being rendered. If we go to 20, then the page of the single product is being rendered. If we go to any page, then the page of the single product is being rendered. So in the page of the single product, they will receive the ID. Whatever ID is here, if it is 1, then it is 1, if it is 2, then it is 2. They will receive the ID. So we will go to the single product. What do we have to do to receive the ID? React Router DOM provides a hook, I told you. that is use params, then use params, save it in a variable, const params is equal to use params, format it here, okay, and you can see params by doing CLG, control shift I, here you are getting an object, here you can see the ID, whatever name you give here, it will come, you have given the ID, that's why the ID is visible, if you give the key, then you will see the key here, okay, so whatever will be here, whether here, It is 34. So, look here. It is 34 in ID. So, we have received it properly. Right? Product page. Come to single product page. So, params dot ID. Or you simply destructure ID. So, here you are getting ID. And here you will use ID. You will fetch data related to ID. Okay? That's it. We have to do this much work. Okay. We have to do this much work. Very good. But to click on product, we have to go on that route. So, for that, we have to In the products page, remove home, remove app.jsx. In the products page, this is our card. Definitely, we should go on that route by clicking on the card. So, we will send it on that route. So, for that, what can we do here? Either we can make it a nav link. But there is no need for that. Here, you can use use navigate. Right? For programmatic navigation, you use use navigate. Do you remember something? Use navigate. and this hook also comes from your React RotterDom, it must have been imported from your React RotterDom, if not, then you can do it, use navigate, and we will save it in a variable, const navigate, the same way to use all hooks, a very similar way, so use navigate, here you got navigate, now here on click, on click, you will make it navigate, navigate, and, Where to navigate? Use the template literal in this way. Slash products slash whatever id will be coming here. Item.id will be coming. So whatever id will be there, navigate to that id. Item.id. Okay. So if I click on this, then our 1, 2, 3, 4, this id should be 4th. So look, we have come to the 4th one. And here we have to show the data of single product 4. Wow. Interesting. Very interesting. Very interesting. And we will do one thing, we don't know which card to hover on. So let's do a little more styling here. Basically, let's group it to hover. Let's put a group hover on this card. If we hover anywhere on the card, I have put a group on the whole card. So if we hover anywhere on this card, then our effect Okay. If we hover anywhere in the card, we will hover anywhere in the card. I have put a group on the whole card. So, if we hover anywhere on this card, then our effect will be applied to this image. Group. Group. Hover. Hmm. Wait a minute. I have written a little mistake. See, if we would have put a hover, then our work would have been done only by hovering on the image. I have grouped with the card. That means, if we hover anywhere on the card, then our hover will be applied. We have to put a group hover. Group. hour, like this, and here, scale, 90, 100, so it will be full, 90, so it will be a little smaller, and, it looks like a glitch, we have to give transition, transition, transition, scale, transform, transition, or give transition all, if you don't know, whose to give, although, transition, transform, will look like here, because we are doing transform, Transition all, if you still don't understand. Transition all, duration 200. So look at this. This is fine. It's looking good. Hmm. It's looking good. So give 400 here. It will look better. And you can do one more thing. What else can you do? And you can change the color of H1 a little. Group. Hover. And here. Text. Blue. You can show this 400 shade. So it will look like a little link. See this. So now if I click on this ring. So the ID of this ring is here. Basically I will navigate there. And we can see its ID here. Now the ID is visible. So it is very easy to get data from the ID. And why is this error coming? Home product. It says invalid DOM property. Class. Did you mean class name? Where did we use class? We have used class name everywhere. Okay. We had ordered one component from outside. This loader one. I think class is written in the loader. Class. So do class name everywhere. Class is equal to go. Class name is equal to say. Replace. Done. Now you don't see any error here. Reload. Now there is no error. Come to this t-shirt. So we have to show the detail of the t-shirt. So for that single product page. So do the same work here. data fetch and this loading etc. everything will be here. So copy the whole thing here. From the product page and paste it here. Yeah. Okay. So what all did I paste? See. Product data will come. Single product data. So remove S from here. Even if you don't remove it, it's okay. But it looks good. It works as you are writing the name. Product means single product data. So here an object will be coming to you. Rest you can check the data and see what is coming to you. So before setting here, let the loading be, our loading will run and the product will be set here. And the response.data will be coming. If you want, you can check what is coming in the response by doing CLG. You can see what is coming in the response by doing CLG. It must be visible somewhere. useState is not defined useState and useEffect will not be defined so useEffect will also be defined very good, reload now what is not defined? xuse is not defined import xuse from xuse now everything is defined now what is not defined? loader is not defined ok Loader component import loader from dot slash loader. What else is not defined? See, now it's fine. So the data has come to you. See, in response, you are getting this data too. So it's fine. It's exactly the same. Response dot data. So your data will be set. Okay. So if you want, you can see the product. CLG product. See this. It was an empty object. As soon as the data came, the whole data is coming, the whole array is coming, when the object was not coming. Okay, okay, okay, okay, okay. We haven't changed this here, we are ordering the entire product here. So cover it in the template literal. And here you have to pass the ID. Where will the ID come from? It will come from here. Here is the ID. You have to pass the ID. The data of that ID will be coming. The data of that single product will be coming. Okay. Let's reload. It was an empty object. And as soon as the data comes, the data has come. The data of the third one has come completely. Because we are on the third, so the data of the third is coming. If we go to the fourth, then the fourth date will come. So we have to show its data here. So to show, let's copy this card for the time being. We will make changes in it. Because we are showing all the data here. So copy it. And paste it here. Okay. So this is done. Very good. And here is the product. So we have to change it from item here. Search from the control app. Item. We have done item dot item dot everywhere. here product.id product.image product.title product.rating.count.rate and here product.price and below price we will also show description product product.description description ok and here we had put line clamp there we were not showing full title here we have to show full title so alright come see how it is looking Wait a minute. OK. Let's reload. Some error has come. I don't know what error has come. Everything is fine. See what error has come here. Cannot read properties of undefined reading rate. Where did this error come from? Okay, we are using navigate here, it will not be getting navigate. Remove navigate. So now here, what else is there, see more. It is not getting rate. Product.rating.rate should be found. Do component once, the problem is in it. Let me check once. Everything is fine here in the image. product.image will be coming here. product.title will be coming here. product.rating.rate product.rating.count product.description product.price Everything is fine here. Then what is the problem? Brother, from this fake store, first of all, copy it from here and see if the data is coming right here. Give me the ID of 3. Here the third one is coming. So title, price, description, category, rating, everything is fine. That's it. So then where is our application stuck? Single product. It is telling some problems in the react router. Here we have not used the react router anywhere. Have you used it somewhere? Have not used it. Do one thing, comment on it and see if our error goes or not. So let's comment on it. It's not commenting either. Error is visible here somewhere. We have made a mistake somewhere. Wait, wait, wait, you will know what the error is now. ok error is not coming now, let's go to the home, let's come to the product, the product is visible and click on it. Now let's render this here, somewhere in between this will be an error, now the error is not coming, what is the problem here, now the error was coming, now the error is not coming, tell me, now come back again, ok, ok, ok, ok, ok, here it takes time to load the data, actually It takes time to load the data, so it takes time to load the data, so this image of the product that we are rendering here will not be getting the image. This is the right thing. So here we have to do optional chaining here. Rest we have put the loading that until the data is not loaded, the loader has to be shown, but still you can do optional chaining here. If the product does not come, then put a question mark here. The product will be there, then only the product image has to be shown. The product will be there, then only the title has to be shown. product will be there, then its rating and its rate will be shown, now there is no need to change here, rating will be there, that means the rate will also be there, the product will be there, then the rating and the count will be shown, the product will be there, then the price will be shown, the product will be there, then the description will be shown, so reload now, it is still coming here, cannot read properties of undefined reading rate, oh man, it should have come now, home products, here our product is fetched, let's come to this, so What is the problem with this rate? I don't know. Everything is fine here. Look, it's coming now. Okay, we did optional chaining, now it's fine. When there was no need to do it. But still, I don't know, there was some problem. If we have rating, then rate should also be there. It's a strange problem. Let's reload. There is no problem now. Let's reload and see again. There is no problem. Okay. It took time for data to come. That's why there was a problem. So here I did optional chaining everywhere. If you were not doing it here, then there was some issue. But now there is an issue here, so you can do optional chaining here too. There is no problem if this is happening. Better you do optional chaining, if there is no data, then it will not be visible and if there is, then it should be visible. Rest, we will not do it this way, we will do proper state management here, then properly when our loader will be true, then it will not run completely and that's it, it will work properly. But for now, you will have to do all this. So this is our, whatever error we fixed, here you can see it properly, do one thing, remove its BG color from here, do we have to give the background, we do not have to give the background, okay. It looks like this for now. Properly you can see the details here. Here in the image. Everything is fine. If you bring it to the side, it will look better. Or it's fine below. Let's do one thing. Let's bring the image in the middle. How much space is the image taking? First we have to see. How much space is our image taking? So here give the image background color. bg red 500 and see how much space it is taking it is taking this much space so let's bring it in the middle let's bring it in the middle margin auto ok so it is in the middle and if you want you can keep everything in the middle it will look better keep it in the middle it will look better flex it flex column it and from item center it will come in between item center because we have done flex column so it will not happen from item center justify center hmm what is the problem now we have to see here also how much width it is taking give it bg red 500 So let's do one thing, let's flex it and flex column and item center it. So here it should come in the middle, it is showing in the middle and do one thing, do its maximum width, do some 120 maximum width, there is 120, do 60rem in the customized way, so it will give an error and say 60rem can be retained as maximum width 240. So let's write 240. What's the problem? 240. So it's coming like this. And now it's looking better. It's looking good. Okay. Everything is fine. Here below it. Here the font size should be a little bigger. Of H1. Instead of 2XL, do 4XL here. So 4XL looks like this. And... below this, this one which is our rating and paragraph, it has given margin wise this much, right? Do one thing in it. Margin from top do 7. So it is coming like this and here margin from bottom do 7 and margin from top do 3. So this will look proper now. See this. Okay. And here in card Give me some padding. Padding Y to 10. So, padding will come from top to bottom. It will look nice. It looks good now. Okay. So, something like this is coming to us. Home page is completely empty. Nothing is on home page. You have to design home page. As soon as it comes on product page, our loading happens. Our data is fetched. All the data has been fetched. Now I want to show the details of the product on which I click. So suppose I click on this ssd card. As soon as I click on it, it will load here. After loading, our data will come. After the data comes, our data will be visible here. Okay. So, go and do the design properly. But don't do it in this. Okay. Where you will be making a proper project. There we will do the design properly. We will do it properly responsive. Although it is responsive. It is properly responsive. Okay. If you look at home, it is also responsive. Your product page is also responsive here. It is properly responsive. There is no problem. Your phone will also look properly. Okay. It is properly visible. There is no problem. It is looking good. Okay. So, it's looking good. So, this is our project. Although, we haven't done state management properly yet. I mean, we haven't done state management. You have read states, but there are some things, like prop drilling, etc. To solve that, we do state management properly. Adjust and Reduce Toolkit. You must have heard of Toolkit. So, when we do all that, it will be better. Dangerous type of e-commerce project, LMS project, and different educational, whatever projects are there, we can make everything. Okay? Movie application. Multiple things. School management application. There are many things. You can make everything. So that's all there was. If you want to do something else, you can do it. Rest, I think everything is fine here. Let's check once. There is nothing in home. We have made a loader in the loader. We have made a proper We have broken the component and we are not spending much line here. If you look carefully, then we are complete in 23 lines. We have also made a component in the product. The product card is made here and we have mapped it here. So for the product card, you can make a separate component here and we have only done this much work in the single product page and this is done. Then app.jsx is also neat and clean. Now this is a small project, so it will be neat and clean. But how will you keep neat and clean in a big project? This will be the thing to see. So this project is complete. We understood the funda of React DOM. And all the confusing things that you must have felt, everything will be clear after this. And then we will move ahead. And we have to understand context. After this, we have to understand state management. So, let's meet in the next lecture. Till then, keep exploring. And further, I am giving you one more task. Context API. State Management. You have to do a little research about it. You have to read documentation from yourself. And you will see that documentation is not understanding. That's why I am saying. Documentation has to be read. You have to try to do it. You will see that documentation is a little bit dangerous. It is not going to understand. So, when you will see the video, I will clear all the things. But at least you have to try to read the documentation once. How does it feel? What does it feel to see the documentation? Is it clicking on anything or not? You have to at least see it once. So that's it for now. You will get the code in this lecture. And bye-bye.
