Podcast Lookup

Build a News App with React JS | DaisyUI, Tailwind CSS & Context API

ReactJS Developers Podcast

  • December 3, 2026
  • 2 h 2 min
  • Episode 28
Episode page
About this episodeWant to build a modern News Application while mastering some of the most useful tools in the React ecosystem? In this episode, you'll…
Want to build a modern News Application while mastering some of the most useful tools in the React ecosystem? In this episode, you'll learn how to develop a News App using React JS, DaisyUI, Tailwind CSS, and Context API.This practical project brings together component-based development, modern UI styling, and global state management to create a dynamic news browsing experience.You'll explore how to organise your React application, build reusable interface components, manage shared data with Context API, and use Tailwind CSS and DaisyUI to create an attractive and responsive user interface.Whether you're strengthening your React skills or building projects for your developer portfolio, this tutorial provides valuable hands-on experience.What You'll Learn
  • How to set up a React JS project.

  • Understanding the project structure and component architecture.

  • Styling React applications with Tailwind CSS.

  • Using DaisyUI to build attractive UI components.

  • Understanding and implementing React Context API.

  • Managing global application state.

  • Creating reusable components for displaying news.

  • Organising news categories and content.

  • Building responsive layouts for different screen sizes.

  • Integrating the different technologies into one React project.

  • Applying modern frontend development practices.

Who Should Watch?
  • React JS beginners and intermediate developers.

  • Frontend developers learning Tailwind CSS.

  • Developers interested in DaisyUI and modern UI development.

  • JavaScript developers learning Context API.

  • Students building portfolio-ready React projects.

  • Anyone interested in developing real-world news applications.

Transcript

From the publisher

This transcript comes from the podcast’s own feed, shown as the publisher wrote it.

Build a News App with React JS | DaisyUI, Tailwind CSS & Context API

00:00—
  1. Speaker 1

    Now we are going to make a news application which is going to be very important for you. I am saying this because until you practice with real world scenarios and face real world situations, concepts will be weak. No matter how much you read theory, no matter how much you code, concepts will be weak. If you are not practicing with real world scenarios. And if you want to make the concepts very strong, then the only solution is to make projects, real-world projects, so that you get a lot of idea of how to face which situation. How to maintain and optimize the code properly. So this project is very easy, but if we make it with proper optimization, then it can seem a little complicated. It has three major goals. First is state management, which you have done properly. State management, context, API, just stand, and then the Redux and Redux toolkit will also come. But as much as we have read state management, you must have done it properly. If you haven't done it, then you can do it. So you have read it theoretically, you have implemented it, but you haven't done it in the project. So until you implement it in the project, you don't get that much idea, that much feeling. So, here we are going to use context API in state management. So, state management is clear to you. You will get proper implementation. You will get real world implementation. And the second major goal which is going to be new for us, new for you, that is daisy UI. We are going to learn a library of react whose name is daisy UI. This UI which you are seeing is looking very beautiful. So, we are making it with the help of daisy UI. There is a library based on Tailwind called Daisy UI. You can use it in React in a very proper way. In 5 to 10 minutes, the whole UI is designed. You have to write a lot of code in Tailwind. You had to write more in CSS. You have to write the class name in Tailwind. Now it is better than that. Use Daisy UI. The components are made. There are better options than Daisy UI. There is Satsian etc. But for now, we are going to learn Daisy UI. So in this lecture, you will be covered in Daisy UI. Okay. So state management, DAISY UI, and the third most important thing is, how to handle API, how to read documentation. We have done API, Fetch, Exios etc. But in real world scenarios, how to make instance, how to read proper documentation related to API. If you are looking for any new API, For example, if you want to create a YouTube API, how will you go to the YouTube API and how will you read the documentation? All that will be clear to you from here. The way we will read the documentation in the news API, we will see how it can be done. You have to do the same process in everything. Okay, if you read any new documentation. So here I will read the news API documentation, I will pick up the API and how to properly utilize it and use it in your application. You will get to learn all these things. Along with that, how to use it by making an exos instance etc. It is not that we will call directly and list the data set here. No, I have said optimizations, so we will do that. Okay. So, these three goals are our major. Rest, the project will be made immediately. You will also make it. So, that is not a big challenge. The big challenge is that how to write code, how to write maintainable code, how to do state management and how to make your instance and work so that code There is no need to debug more. Do changes in one place and it should be working everywhere. So how to break the code? All those things. The rest of the application is very simple and not as simple as it seems. So here basically news is being listed to you. These are all the news. You can see it here, you can also read it. And here are three dots. If you look carefully, you will see only two lines, not more than two lines. In which more than two lines are being titled, there are three dots. So you get all this from Tailwind CSS. And here we are showing the description up to 3 lines, not more than 3 lines. So keep understanding the UI a little so that you can make it yourself in the project. And this is how you can see it. Are both the same news? I don't know, maybe the same news is coming from API. Something will be different. And if you click on read more here, then any website related to that news, the news that is posted on that website, because we are taking news from all over the world. Any news channel will be somewhere, any news channel will be somewhere. So all news channels are coming to you by combining. World News. And here you can see that news from where it is coming. Now this news is looking a little different. Let's try this news once. See here. This is the news till today. And it is looking something like this. So you can go and read it properly by clicking on Read More. So this is the work of API. It will give you a link. Redirect it to the link. So this is not a big issue. Here you have categories list. Here if you click on business, you will get business related news. Along with that you will see the loader, how beautiful loader we have installed. So we did not design it ourselves, we got it made, so I installed it. So if you click on business, you will get all the business related news. If you click on entertainment, you will get all the news related to entertainment. And if you want to see general, you will get all the general news. If you want to see sports or technology related, you will click on technology. And you can see all the news related to technology. All these are news based on technology. And along with that, I have given the search feature and this is very important. I will do the control shift I and along with that I will show you the network tab. So our network tab is also open. Your console will open here. You click on it. Okay, why are there so many errors? Okay, there is no issue. So here there will be no load of images. That's why this error is coming. So here you have to come to the network tab and after coming to the network tab, select the option of filter, so that you can see how many times the API is fetching. So I reload, now as soon as we type here, it will be searched here. But here I have put debouncing, which I had told in JavaScript. I have told debouncing in sorts, or you must have done it somewhere. So in reality, we will see how to implement it in the project. What does debouncing mean? When you are searching here, If you write A, it will search. If you write B, it will search. If you search so fast, then how much more API will be hit? And the more the API is hit, the more your cost will increase. You have to save cost. So what can you do here? As I am typing ALPHA, it is searching after 500 milliseconds. Means, as I stopped typing, it is hitting the API after a few milliseconds or milliseconds. So that our cost is saved. If I would have written alpha, then it would have hit the API on A as well. It would have hit the API on L as well. P, H, A. It would have hit the API on all of them. And 5 APIs have been hit so far. But here only one API has been hit. One was done when it was reloaded. One was done when it was searched. So I stopped the entire type. Then after 500 milliseconds, your API has been hit. And it is working in a properly optimized way. If I want to search for news related to India, then I will write INDIA here. And as soon as I stop, after 5 milliseconds, it will search here and give you all the data. So this is done. And I have given this for show-off. Rest, your task is that you can show top headlines. By clicking on it, you will get a drawer from the site and you can show top headlines there. So this is your task. Rest, we have done all these things here. And from here, you have some specific filters. Rest, you can search here. And the whole thing is synced. You see carefully, we have made a different component. In the navbar, this is your search. And then, this category component is a different component. And this, where news is visible, is a different component. So, three places are divided in a different way. What parent, whose child is it, we don't know all that. But here, we are not doing props drill. Here, we are working in a global state. Or we are working in a store. From where, this is all synced. So, that is called state management. So, you will learn all these things in this project. And we will start making it very properly from scratch. Because many people have problems in UI. So, they will learn Desi UI. And along with that, we will optimize it to the advanced level. Okay. Rest, you should know state management, context API, etc. It is not that I will sit and explain from scratch. Then fetch, exios, etc. You should know this. Rest, Desi UI is new for us. So, I will explain it to you properly. So this is your project, and this is me, and you're sitting here. So come quickly, let's start making our project, which is MKL News. So now wherever you're organizing your code, open that folder in your VS Code. I'm organizing all my code in the React folder, and all this code, whether it's project code or any the concept, the topic I am explaining, the code of that lecture, you will get all the code in one place. There is a link in the description. You can check it out. So, don't worry about the code. You have to understand it carefully. Okay? So, here we install a new project. We come to our browser. And here you have to search. We are going to use Tailwind. So, let's do one thing. We come to the Tailwind website. And I have told you this many times. You have to come to documentation. It will be on using wheat by default. So, go to using wheat option. you have to install it from here. First of all, we will install the Vite application. So you have to click here, both the commands will be copied. Come here and paste it. I have done this paste and it says, are you sure you want to paste two lines? Yes, I want to paste both the lines. So this is also pasted and the name of the project is My Project. I had to change it a little bit, but it's okay, there is no issue. So let's react here and select the JavaScript variant and Experimental, we will let it be. Do we have to start now? No, we don't have to start. And we have to go inside CD My Project. go to myproject folder. So this is our bit installed basically. Myproject folder has been made here and this whole folder structure has come. We have come inside my project from CD my project. All these things come to you, that's why you have come here. And we will install the tailwind, we will copy it and paste it here. And let's move on to our next work until it is installed. So you have to copy it from here. And if you are using VEED.CONFIG.JS, then VEED.CONFIG.JS will be here. So you have to paste it here and install the plugin in this way. I am doing it from here, you can do it too. Select the CSS file and import it in CSS. The main CSS file is index.css. I will remove the whole CSS and paste it here. I will remove the whole app.css as well. Because we are going to use Daisy UI and Tailwind CSS. That's it. So, we have removed app.css and index.css. Alright. We have done NPM Rundev. Now you can start working. I will cut it and come here and check once that what is running properly. And let's do one thing, Daisy UI is also installed here, so let's install it. So come here, search Daisy UI and here is your Daisy UI. So Daisy UI is also a library, like Tailwind CSS is yours, you use Tailwind CSS, similarly you have Daisy UI, which you use Tailwind CSS, then what do you have to do? Here you have to write the class name, come here in app.jsx, And here you work in this way. For now, I will clear all the things. Clear everything quickly. Remove all this too from here. So here you have to make a heading in this way. And here you have to design. So here you will write the class name. BG Red 500 and something something something. Suggestions are not coming. Tell me. So let's reload once. Just reload. Reload app. Alright. So what happened here? Did we reload something wrong? Okay. Okay, okay, okay, okay, okay. We did something wrong. Let's see. So, CLS. And are we getting suggestions? No. Control shift P. Reload window. We had to do this one. Okay. So now you will get the suggestion. So this is how you style. If you want to style the heading, you will have to write all the class names, then you will style it. You will do it according to yourself. And if you want to make a map bar, then you will make a map bar by writing the whole class name. So basically if you go to the core, then you are using the whole CSS. CSS should come, only then you will be able to use Tailwind CSS. Now here you don't need much of Tailwind CSS. You don't have to go through all that. Although you should come. But I am telling you the way how you can design a UI in 5-10 minutes. So for that, you got a library of DAISY UI. Where you will get tailwind classes written. You just have to copy and paste the whole component. UI is done. Okay, tell me how to use it. Click on how to use and it will tell you how to install it. So, npm i slash ddziui. And it is asking you to install it as a dev dependency. What is the difference between a dev dependency and a dependency? I have told you. Dev dependency means you are using it only during development. It will not be installed when you go to production. Without it, the whole project will be running. Okay. package.json has dependency and all these have dev dependency. So if I install it here, it will be added as a dev dependency here. See carefully. As a dev dependency, you have added a desi UI here. All right. So I don't think you need to explain all this. You know all these things. And now what we will do is So now we have to import it in app.css like we did in tailwind. So here it is telling that you have tailwind above and daisyui below. And daisyui will work only when tailwind.css is installed. Because daisyui is based on tailwind. So first tailwind.css and then daisyui. So here I am doing copy and here I am doing paste. Where? In index.css. At this place. Okay. So this is done, let's run our project from npm run dev. This has also been run. And quickly open here. Here it is open. So we have to make this and this is also made. So basically nothing is made. Daisy UI has just been set up and Tailwind CSS. So now we will stay on this Daisy UI website because we will quickly make it by searching for components from here. So first of all, we have to create a new bar, this new bar. So you can search for something like this new bar here. Come to the search option and search for new bar here. Okay, so you have this new bar option, click on it. So here you will get different different new bars. So this new bar is needed, this is needed, what is needed, you can see here. So, so, so, so, this is the new bar, right? Yes, this is the one. In this, basically, we will remove this user icon and put something like this here. So let's take this one. Here you are not using HTML. No, we are using JSX. Exactly. So here you have to come to JSX. And this whole thing has to be done from here. Copy and paste from here. Where to paste? Here. All right. Okay, one more tab of VS Code is open here. So that old project is running. Old means this project is running on it. So I come here. And... So let's make a component here. component folder. This is an assets folder, so delete it, it is not needed. So here we will make a component folder. component and here our navbar will come. navbar.jsx Okay, rafce and this is our navbar. Look, the navbar is made. Did you see how fast the navbar was made? Is it really made? Yes, it is really made. I come here in app.jsx and show you by putting a navbar here. Navbar. Look, our import is also done and I hide it. So you can see it clearly. I zoom in a little bit. Okay. So look, you have a navbar. Wow. Wow. Interesting. So now we will come here in the navbar and Here are some of the classes of daisy UI. For example, it is not using the nappbar here. Because you don't have it in tailwind. So it has used all these things. Button ghost button is used here. So all these things are already made of daisy UI. So if you are thinking like this, then you are thinking wrong. We are using tailwind CSS here. Basically, the component is made and pasting will work. For that, you will also have to install daisy UI. Because there are many classes of daisy UI here. It is made on Tailwind, but it also has a lot of classes of Daisy UI. So you have to install it first, then you can use it. So this is done, here you name it as mklnews. You can give anything you want, there is no issue. And from here we will remove this profile. We will remove this setting logout. So here we don't need all this. I think if we remove this whole thing, our work will be done. And this is an image. What kind of image is this? Drop down. We don't need this either, I think. This is also useless. This is just an input box. And we need this mklnews written here. Which is coming here. Perfect. Perfect. And we need one more thing, which is this. I have given this as useless. Although you have to implement this. So we will come to JSX. So find it. Which is this? The search button is next to it. Means below it. Can you see the search button here? Find it quickly. If you can see any input box, search, etc., then tell me. Can you see it? This is the center of the navbar. Okay, is there a center in this too? Yes, this is the center, so it will be in the end. Navbar center, navbar end. See, there is a button in the end. Okay, and ghost button. So I think this is the ghost button. So, let's pick up the last button from here. I think this is the one. So, let's do Ctrl C here. See, there are two buttons. So, here one button is this and the other one is this. So, let's pick up the last button from here. The last one should not be this. So, let's pick up the second one and see. So, Ctrl C and paste it here. Okay. And let's see what kind of UI we have made. So, see, it has come here. Okay, proper. Absolutely proper. Okay, have you seen the padding from the side here? If you look carefully, this is not padding. This is not padding. How will it show? How do I show you? How do I show you? Can I show you like this? Yes, I can show you like this. Look carefully. This is not padding. If it was padding, it would have been completely stuck. But this is not padding. I have done it in the center basically. I have set its maximum width and I have put it in the center. So this is it for now. And as it will be less, it will shrink in some way. So, you should know all these styles from the beginning. So, you should know all these styles from the beginning. So, you should know all these styles from the beginning. So, you should know all these styles from the beginning. So, you should know all these styles from the beginning. So, you should know all these styles from the beginning. In this too, I have to set the maximum width in this way. Let's say I will set 60rem 70rem whatever it is and I will do it in the center. Then I have to do the same in this card component too. Basically, the buttons etc. are given and then I have to do something like this in the card component too. So I will do one thing, I will make a wrapper. Okay, I will make a wrapper in the component itself. Wrapper.jsx rafc and this wrapper will be taking our children. Children and these children we will So you know how to use these props. So whatever we pass in this wrapper will be rendered as a children. So if we pass a navbar in the wrapper, let's say I import the wrapper and wrap the whole component in it. So I wrapped the entire nap bar inside the wrapper. So now whatever I do in the wrapper, it will be visible to you in the nap bar. Because inside the wrapper is your entire nap bar. See here. Now you can see the entire nap bar. And the wrapper is also attached. If you are not believing, then come here in the wrapper. I give it some class name here. Class name padding x10. So see this. Padding came on the side. So whatever I do inside the wrapper. So all the components used inside the wrapper. I have applied that wrapper wherever I have used it. It will be applied to all. If I put the wrapper here and let's make a page together because there is also a page need. So here we have made a page and inside the page we make a news page. News.jsx rafce and here in app.jsx navbar along with here we will get news. So you can wrap here too, there is no issue. And you can do it here too, there is no issue. So, I have wrapped it in the wrapper. Now, the style I have given in the wrapper is also being applied in the news. Because as a children, we have passed the news component here. And in the navbar, the entire component of navbar has been passed. So, I will only change it in the wrapper. This will also change in this. Look, here also you have applied padding and here also you have applied padding. Okay. You must be thinking that it has been applied separately but the padding has not been applied separately. Something has already been given in the navbar. If you look carefully. So we have to fix it. So you must have understood that wherever we use the wrapper, the padding will be of X10. But we don't have to do this. We have to set the maximum width here. Suppose we set 70rem here and I will show you how it looks. 70rem is something like this. Now I will bring these two in the center. To bring them in the center, I will do margin auto. and it will come in the center. See, it came in the center. Okay. And next to it, there is some padding etc. I think it is in the navbar. So, it has not given the daisy UI, so we can't do anything about it. Isn't it? The navbar one, which they have used in the class, they have given it in this. So, there is no issue. Here we have given 70RM in wrapper. So, here it is. 70RM has been applied. And what can we do at the same time? Why is this yellow line coming? It is saying that you can also write 70RM as 280RM. No problem, let's write 280RM. As you say, 280RM will be equal to 70RM. You can see in the calculation. Basically, 1 means 4 pixels. So 280 means 2x4. So it works in this way. You can go to the Tailwind website and see what it means. Okay. So, this is how we are getting it. So, our map bar is made. What else do we have to make? We have to make some buttons. So, we will get the buttons made here. Search for buttons. Buttons, buttons, buttons, buttons, buttons. Here you get a lot of buttons. So you take this one button. Neutral button, primary button, there are many buttons. So which button do you want to take? Okay, see the theme. Now our by default theme is set here. Here too or here too. That is our dark theme. So you set the dark theme here. Because according to the dark, the color of the button will also be different. So where will we set the theme? Oh brother, here it is. You see this dark theme. So in dark theme, see the color of the button is like this. Primary one. And we have set the primary button. So let's take the primary button from here. So we will take this primary button. See, we just copied a small component. And here, we will make a new file in the component. We will name it category.jsx. And here all our buttons will come. Okay, take this. So see, the buttons are not visible here because we have not used the component. We have made a category component, but we have not used it in app.jsx. So in app.jsx, we will have a category just below the navbar. So see, there are three different components, but in all three, we are working by linking the news. By clicking on the category, our news is fetching, data is being set, then our data is being fetched and set on the search as well. So how will we do all that? So through state management. So first let's make a little UI. So see, it came here. Now see, it is coming to the side completely. Now we will have to do the same work in this as well. Maximum width 70, then margin auto, all this. So we have made a wrapper for that. So here we will wrap it in the wrapper and our work will be done. Okay. Wrapper. And here we have wrapped it. And here our work is done. That's it. Keep doing this and your work will be done everywhere. Okay. So in category we have done this. And where have we given color? Which is coming like this. Okay. Here we have given color. BG red. So remove this red. Otherwise it will be in all. If we will give it in wrapper. Okay. So it is coming in this way. You can see it. And we can do one thing, we will use a little different color of the navbar here. Because BG base 100 is a little mixed together. So we will have this kind of color here. And now see this has disappeared from the side here. Because we have put a wrapper in which the maximum width is 280. So this is how much our background color is being applied here. So to fix this, we have to take an outer dip and we will give the full background color in it. So do one thing here, take a div like this, and this div will definitely have a width of 100%. So if we give a background color in this, then this whole background will be applied in 100%. Right? So remove this bg base from here, 200. And come here, class name, and paste it here. Alright. So now I think it will come here completely. Sorry. So see here, it has come here completely. Now let's see how to work in the category. So here we have one button. In the same way, multiple buttons will come to you. And we will have different categories. So you can see which categories you have to list here. So first of all, we will come to the news API. Because until we see what categories are there, we will not read the documentation. How will we know by then? So you will get one newsapi.org. We have not used newsapi.ai. We have used newsapi.org. So you can search newsapi.org like this. So I think you will get it at the top. It went down a lot. So you can search the whole newsapi.org like this. Still, I don't know why it is ranking below. So come to newsapi.org. And here you will have to log in first. Then you will get the API key, so log in so that you get the API key and I log in here quickly. Email ID and password etc. were already saved here, so I have logged in. If you have not used it before, then you will have to make a new one and then you can log in here. So see the request limit here, I have used it before to tell projects etc. So here you will see a lot of heat. So there is a limit to this, that you can hit so much, otherwise after that you will have to wait for the next day, then your cover will be renewed. So use it a little carefully. That's what I will say. Rest, there is so much hit that you can easily make a project. Rest, if by chance it is over, then there is no issue. You will have to wait a little, the rest of the work will be done. Alright. So here you are getting API key. You note this carefully somewhere. I will tell you how to work. So here click on get started. and you will get the documentation, so click on the documentation and here you will get the documentation, it was here basically, ok, see this get started documentation is nearby, when you click on the documentation, then you will get all the things here, how to use it, authentication etc., you will see the end point here, come to everything, so here you will see the API, see this, in this way you will get API, So you will use this API, and in the key, this is your API key. So according to your API key, it will see how much you have hit. Otherwise, if everyone hits, how will they know? So your API key is very important. You have to take care of the API key here. If your API key is not coming here, then you can go to your API profile and see. So here, as soon as I hit this whole API, you will get the whole data here. Now how is it getting, what is it getting, I will tell you now. But for now, look at the documentation here. Look at the little documentation that what are the other things here. Look, one is everything and the other is top headlines. So I want everything. I want news from the whole world where I can take news according to my query. So what I have to do here, look, you will get this API you are getting title, description and content. You can see what is getting here. Here you are getting this example response also. Here you get total result, status and also articles array. And in articles array you have author, title, description, URL, URL to image, published ad and content. and also source ID name, you are getting all these things. So in this way, you have this coming and you have to use it to list these articles. And if you look at the top headlines, then you will see in the top headlines that how the example response is coming. Response matters a lot, like here the author is coming, the title is coming, the description is coming. And also the URL to image is coming here too. So both are the same, everything is coming in the same way and the top headlines are also coming in the same way. You come and see what the source has done here. So the category is given here, Business, Entertainment, General Health, Science, Support, Sports and Technology. So if you come to the source and call the API, then the title description is not coming, the name key is coming here. Key is important. If you think that by making a whole state and taking all the data in it, everything will work, then it is not like that. Here you will have to separate a little. Okay. So, this is not going to affect us. Everything will be done by everything. You can see how it is using everything. http: / / newsapi. org / / version2 So, this much will remain the same. / / everything This is important. In top headlines, you had / / topheadlines Here, you can see top headlines. And in source, you also have Top Headlines and also the source. I don't want Top Headlines. You have to implement the Top Headline. Which I told you to come from the side on the button click. You have to see the Top Headlines there. So you have to do that. In everything, our work will be done. Here slash everything. And we will work by giving a question mark and query. If we write India in the query, then news related to India will come. And if in category, let's say here. In query, we will work on category as well. If we want sports, then we will put sports here. Sports will come. I will show you by doing it. See, I have copied the whole thing from here. I will come here and paste it. And this is also a get. So remove it. Otherwise, you will not get a response. So query, see here is bitcoin. And then after that, you have API key. So if I do India in the query, then you will be getting news related to India. Okay. This is the whole news related to India. If you want, you can read the description here. You will know that it is related to India. Then if I do something here, let's say I want news related to Tesla. So here I have searched for Tesla in the query and here I will get news related to Tesla. See the title Tesla is fighting the AV sales. So in this way you will get all the news by doing the query. So with one API, all our work will be done. So now how will you handle this API properly? We will see that in the code. And here you can find out the categories that you have given here. language, sort by pages. So, they have given everything that how to sort, publish that, that means how to sort by time, that latest news should come first, old news should come later, old should come first, or popular news should come first. So, you can put sort by here. They have also given here that how to do it. They have given somewhere. Look, query apple, from, from when to when, you can put this too. Also, it has given sort by, popularity. So, it will be sorted on the basis of popularity. If you read the documentation, then you will get a lot of things. This can be done in this way, this can be done in this way. Everything is in the URL itself. It is in the API itself. How you are hitting the API, that depends. So, here the next one is the same. You have to work on everything till this far. Or remove everything because top headlines can also be used. So, here let's assume till version 2 is the same. Because till version 2, it will remain the same in the top headline. And this is basically the domain, which is the same. After that, your API will remain the same. So we will save the API in a different way. The same API has to be used everywhere. Then there is the middle URL. Everything, what are you putting in the query, on what basis are you sorting, all these things. So if you have learned to handle this properly, your project has been made, then here you can read what is what, like you have a source here, domain, from, to, you can mention, you can mention language, in which language you want, sort by is here. base size you can mention that means you can also make pagination this API supports pagination so you can also make pagination but to make pagination you should know a lot of logic so on pagination I will bring a separate video where we will discuss proper pagination different types of pagination come infinite scroll pagination then previous next pagination and then bottom pagination button pagination comes there dot dot dot you must have seen so different different pagination are there segment pagination so all those things we will discuss some other time Then in response, status, total size, articles, and here author, title, description, URL, URL to image, publish, content, you are getting all this. Rest category I saw in source. So category, you can remove from here which categories are there. Rest work we will do with query, not with this. So these are so many categories, so I will copy it. And here I will make an array of category. const categories I will create an array and map it, then all our categories will be listed. We have to do the dynamic work properly. It's not like we are making single single buttons and then we are doing it in a different way. We don't have to do it that way. So look, our business is done. So our business came here. After that, we got entertainment. Alright, this is entertainment. After that, we have a general category. So This is general. And. Okay. First I put this whole comma. Now I will copy paste here. So this is health. Health. Then after that science. Alright. Then after that sports. Hmm. Okay. Then after that technology. This is also okay. So here we have all the categories. Now we will map the categories here and our work will be done. That's it. Okay, it will work with only one button. So do I need this div? I don't think so. Remove the div from here. A little too much has been removed. Okay, so here we will do the map. Categories.map and there is a higher order function. So here we have passed the function in it. Do the return carefully, otherwise you will not get anything in the UI. Okay, and here you will have one category coming. Category. Okay, I wrote the spelling right. So you have to show the category that is coming one by one. All right. All right. So is there any error? What can be the error? Think and tell me. Return is not defined. Okay, spelling is wrong. We have misspelled. Return. Okay. Okay, we have to give the key too. So here we give the key too. Category is unique, so let's give category to key. You have to give a unique key, you know all this, I will not go to tell you all this. So this is ours, let's keep it open, it will be useful to us. So let's bring it to the center. What can you do to bring it to the center? To bring it to the center, we have a wrapper here. So we have set the margin auto to maximum width in the wrapper. So let's give it a BG red pass. So this is the whole background so far. So if we want to bring it to the center, then we will have to do something here. In the category, we will wrap x in a div. And here we will set the class name and margin auto. So it will not come in the center because its width fit content. So I think it should come in the center. Alright, it has come in the center, but it is getting bent down. Basically, it is getting wrapped. So to stop the wrap, make it flex, then I think it will work. But now it is going out of the boundary, so I don't want to send it out of the boundary. So what I will do is I will scroll it in the overflow. I have kept the width fit, which means that the width of this will be the full button. Assume that two, three, four buttons are coming in between. So the width fit content means that it will take the same width as the button. Assume that you have a button. your button will be full in 30 rem so width will be up to 30 rem now 30 rem is the width and if you make the screen smaller than 30 rem then definitely it will go out so I want it not to go out so to not send it out what I will do here I will do auto in overflow x means when the width is small then it will start scrolling ok is it scrolling? no it is not scrolling it is still going out So, I think I have to give maximum width here. Width, width. And maximum width full. So, now I think I should work. Maximum width full means, what did I do? Maximum width here, full means 100%. So, its width, means if it is this much width, then it can be this much maximum it can't be more than that if it will try to go more than that then it will scroll like this ok basic CSS now I am not going to explain CSS for CSS I will not even come after preparation that how you have to explain CSS so here in this way you have to scroll from technology to business see technology is here business entertainment general health science sport technology so maximum width I have given full means max to max this It can be full, it can be 100%, it can't go more than that. So here it is more than 100%, now it is more. So if it is more, then I said what to do when it is more, do overflow x auto. Okay, means scroll. If I keep overflow x scroll, then it will always be scroll. If it has space, then also it will be a scroll option. Whereas it already has space. But here I have auto, so when there is no space, then overflow option will come there. Scroll option will come basically. So when I will make it small, then see this scroll option is coming. Like this. So, in mobile device, the user can scroll like this. Right? And I will do one thing. I will give a little padding or margin from side to side. I will give margin. Margin. Give 4 from X. See how it will look. It looks like this. No. It will not sit with margin. Right? It will not sit with margin. Give 4 from padding X. And see how it looks. So now it's fine. Now it's fine. Reload it. And do one more thing. First of all, remove the BG red from the wrapper. It doesn't look good. So now remove this. Because we don't need this. This is basically coming in the mobile device. So in the mobile device or in the tab. So in the tab or in the mobile device, we don't need it. And if you want it in the PC, then you can do it without using it. You can do it with the mouse scroll. But this is for mobile device. So in mobile device or tab, you have screen touch. So you will do this with screen. So it doesn't need this. This scroll bar doesn't need this. So for this, Tailwind doesn't support this. So you have to write here in CSS. In index.css. So in index.css, I will write. Let's make a class. Scroll bar none. Okay. We have made a class of scroll bar none. So wherever you will put this scroll bar none, the scroll bar should move. So, what can we do for that? If we do scrollbar width none, will our work be done? No, it didn't work. Okay. Okay, where did we put this? Where is our brain? Tell me. It should work by doing scrollbar width none. Come to scrollbar none class or in navbar and put it. Not in navbar, it was in category. So, in this place, you put scrollbar none. And see, it has moved. So now it is scrollable and it is coming in this way. So our responsive has also become proper. This is your maximum. Basically, how much will your mobile weight be at least? 300 pixels, 400 pixels, it will be bigger than 400 pixels. So this is your responsive. If you want to make it more responsive, you can make an icon here. As soon as it gets smaller, a menu icon will come. I have taught you how to make all that. So give a little gap here. Give a gap of 5. See, it will be made very soon, but I am explaining, that's why it takes time. Okay, so this is something like this, you have come here. So this is also made for you. Now if you want, then here you can give some padding from top to bottom. But I will not recommend here to give padding. If you want to give padding, then here you can do something like this. I told you production strategy. Here you can pass the class name as a prop. And here you can you can pass padding. Suppose I want to give padding y of 10. So I will pass padding here as a props and here I will receive as a props. So these are all the things that you have to learn. Making a project is not a very complicated task. Okay. Doing all this takes a lot of time in the project to optimize. So here something like this and like this and here like this. Okay. So whenever you pass your class name to the category, it will come here and you will get it. So see this padding came from the top bottom. Alright. Now what to do here? Now we have to make some cards here for news. Where news will be seen basically. Okay. So for that we come here on daisy UI and search for card. So let's see what kind of card it is. So this is the card and this is also a card. What kind of card do we need? So here we basically need a title, a description, that's it. That's all we need. So title and description. So for that, I think this card is also enough. Title and description. Okay, this one is fine. So come to JSX, copy it from here. And after copying, here you had pages, right? In the page, here is news. And you can make a different component for the card, but I don't think it is needed. It is a small component of news. Now, if you make a separate card component, then you will write code in 10 lines in each file. It won't look good either. The component can be a little bigger. If it is big, then we will put it separately. But I don't think it will be that big here. It will be a little big. So, cost, news card, news card, and return. By the way, we could have done it here too. We could have done our work here too. But if we make a separate component, then if we want to, we will put it in a separate file. Our work will be done. So, here is the news card. And we will use this news card here. Here. Not like this. Like this. Okay. So here you have some news like this. And what to do with it? Tell me quickly. We have to grid it. Okay. Grid. Give column 4. Something like this. And I think the width of the card is set. It has given width 96. So remove this width. So it will take 100 percent and it is also responsive. Wow. Wow. Interesting. And here is a little gap. Give me a gap of 1 rem, that is, give me a gap of 4. So it looks something like this, isn't it? Okay. You can give a little more than 4. So it will look a little like this. It looks better. Okay. So now we will fetch the data here. After fetching the data, we can do our work here. And its color is a little different here. You can give it a little different color. Like in the card, BG base 100 is done here. We will do 200. So it will look a little like this. And it looks more proper. And footer you can make here. Like I have made a footer in it. But I did not show you. So this is a footer. So take any random footer. I have not put any link in the footer. Just for design I have given here. So you are getting a footer made. That's why I have put it. Otherwise I do not waste time in making it. So search for footer here. You will get multiple footers. Whichever footer you want to use, it will be responsive. It will be responsive. So use any footer. Which footer do you want to use? Which one do you like? So if I want to use this, I will use this. We will copy it from here and make a footer component here. New file footer.jsx rafce rafce and This is our footer. And why is this error coming? The footer is open here and the footer is closed here. There are two or three components here, so we will have to make a fragment here in this way. So here we have a fragment. The footer is quite long. Hmm. Okay. So this is our footer. We also use the footer here in app.jsx. In the last, footer. Alright. So now see how the footer is looking here. So something like this is looking. Okay, the footer is looking like this. And if you reload, then all the errors and everything went. And here it is coming this side. So it will also have to be wrapped in the wrapper. So here wrap it in the wrapper. So see this came in the middle. But again, the background is also wrapped here. So for background, BG base 200 is there. You have to make a div on it. And this div has to be given in the class name. And cut it from here. And go to the last and give champ. So now it is perfect. Okay. And there should be a little padding below this news. So we will receive the class name here in the news as a props. And we will put this class name here. Okay. So it takes a lot of time to do all this. Rest, if you have done it once, then you are debugging in the code at any time. You can do it very easily. If you have maintained the code properly in the first time, then when you come to see the code in the second time, you will understand it properly and you will be saving a lot of time. So add the class name here. And where did you use news? Here. So here. Okay, why am I giving the class name from outside? I can also give it from inside. But it is possible that I have to use the news component somewhere else and I don't need padding there. So then I will remove padding inside the component. So it is better to make a class name outside. Whatever extra class is there, whether you want to add padding or border, we will do that from outside. So class name and here you just have to give padding bottom of 10 and that's it. So, look at this. It came in this way. So, overall your UI is made. And how quickly it is made, it took me time to tell you. But if you make it yourself, you just have to copy paste and you just have to optimize it a little bit and your work will be done. So, this is done. Okay. Now, the navbar is going up when scrolling. So, let's fix it first. So here in the navbar also a little class name and here we will pass the class name quickly class name class class name all right and here in app.jsx Now what should I do to stick it up? I can do position absolute, but then the content below will go up. So we can use sticky. If the height will be properly managed here in daisy UI, then this sticky will work properly. So see it is working properly, but the z-index is a little less, so it is going backwards. So we will increase the z-index a little. So see this is fine now. I want to stick this a little bit up too. So can I stick the category too? Yes, I can stick it. I will give it sticky and if I give zero from the top, then it will stick up again. So it should not be like this. I give it 14 from the top. So is it sticking? It's not sticking, it's not sticking, I don't know. So here is a wrapper on it. This is the problem. This is the problem. So, this is really a problem. There is a wrapper here. So, the class name is being applied here. So, we have to put a sticky in the parent div. So, what can we do here? So, here we can do this. Although we can pass the class name to the wrapper. But then the prop drilling will be useless. Here we can make a div on top separately, but if we make a div, then the game will get spoiled. Or it won't get spoiled. It won't get spoiled. Let's try to make it. Okay? Or you could have wrapped the component on top. You have both options. You could have wrapped the div on top of the component. Where you were using the component. There. Here. You can also work by wrapping the div on top of it. But let's try to do it here. It should be done. Like this. Class name. Alright, so remove this class name from here, add it there, and now let's see that it worked. So you will have to see a little bit, you should know this styling so much in CSS that you know that you have to put it on your parent here, otherwise how will it work and the height works according to someone here because It doesn't work all the time. It should have a proper fixed height. Only then it will work there. Now because here we are using daisy UI. So here it is properly maintained. So here it is working properly. Otherwise, if you would have done a little bit of shaking in height, then it would not have been working. And parent has to pay attention to this. It had a wrapper on it. Earlier we had passed the class name here. That's why it was not working. So now it is working. Okay, look at this. But it is going back. So to bring it forward, here is Zed. Let's do 20. So look at this. And its background color will have to be given a little. So by going to category. And deep anyway, we have to put it because we have to give the background here. And actually, don't give it here too. Give the background here. BG base. Come to app.jsx and here BG base 200. So now. We have given 200. 200 is not looking good. BG base here you try by giving 100. See how it is looking. So this is also fine. Okay, this is going a little higher. Because Z index is more than this. So this is looking a little higher. So reduce Z index to this. Increase this to this. Increase this to 20. And increase this to 10. So it will go inside from below. See this. Okay. Great. It's looking proper now. It's sticking on top. Good. So now it's looking good. So everything has been made properly. The whole UI has been designed. Now let's talk about logic. How to write logic and how to do what. So first of all, we do the fetch work here. We do work related to API. So that we can get data and we can use data. Because if we use data, then only we will understand how to use context API etc. So first of all, let's do the fetch work here. So where will we do the fetch work? We have to fetch data in the news, so let's come to the news. There is no need for the app, there is no need for the navbar, remove the category too. So here we will fetch data. So const fetch data or fetch news. And here we will fetch news and use of xuse. So now before that, we have to set up the XEO. Before calling API, we have to set up the XEO properly, only then we will be able to call API here. So NPM i, XEOs, and XEOs, I have taught you properly how instance is made. If you have forgotten, then you will remember now. So if I do it like this, XEOs, and put my URL here. Where is it? Here it is. So I come here and paste this URL. So will we be getting data? Definitely we will be getting it. There is no doubt about it. So we will await because our async is happening. And const response is equal to and here let's do CLG and see what we are getting in response. And we will have to call fetch news. So use effect and here hmm At this point, we will call fetchnews and leave the dependency array empty. So fetchnews will be called and we will get the data. Await does not work empty, you will have to put async here, you know all this. So let's come here in our project, reload and check with ctrl-shift-i if we are getting the data. Exios is not defined. Okay, we did not import here, import exios from exios. Okay, so let's reload. You can see the data in response.data. You can see the data in response.data. You can see the data in response.data. You can see the data in response.data. You can see the data in response.data. You can see the data in response.data. You can see the data in response.data. You can see the data in response.data. You have to list all the articles here. You have to list all the articles here. You have to list all the news here. Then as soon as you click on health, the API will be called again. Now the API will be called. Now if you make a state here, then how will you render here? Because if you fetch here, then you have to set the data again. So the data that you have, which is being shown here, should be global. That's why you can do it. Otherwise, look, let's say I make a state here. and here you have the whole dataset and we have listed the data here. Whatever data is fetched is being listed here. But if we come to the category, there is a category in the component, then if we click on this category and fetch the data here, then after fetching the data, if we set the data in this, then how will the data be used here? This data is being used here. If we set any other data in the category, then how can we use it here? So we have to keep this data global. We have to use this state of news set globally. Then if we set data here too, then you will have a re-render trigger here. Then there is a search component, there is a search in the navbar. In search, we have to fetch data in the same way. After fetching, you have a list. It is happening in the news. You will do fetch in the navbar. search for it in Fetch and Appbar but you have to do it in News definitely you have to make global state here otherwise there is a lot of problem here ok so for that you have to manage here is that you have to make state global state using context API you can also use just stand I am going to do context API in this your work is to do just stand because just stand is more simple than all these things So I hope you have seen the video of just stand and you will implement it with just stand. So do it before the context API and then do it yourself with just stand. Ok. So make it. We got the data. Look, we have come to fetch the API. We are getting the data. But we will optimize it a little more. Look here in Axios, this one is completely the same. So we will write this everywhere. It doesn't mean anything. Wherever we have to call, we have to write this everywhere. So we will not do this. And then the API will be the same everywhere. So we will make it an instance and keep it as an API so that it is not public and no one steals it. So first of all, let's make an exuse instance and then we will set up the context. So here in SRC, let's make another folder called Configurations and here first of all, let's do the configuration of Exuse.js and here import Exuse from Exuse and Exuse.create. In this way, we are creating an instance here. Here we will give you this base URL. What will we give for the base URL? will be the same in every API call. Which is this. This. So this whole thing, whenever you call API here, it will be the same. So this will be your base URL. After that, you can give more timeouts here. Like I gave timeout of 5000. 5000 basically, it is taking in milliseconds. Keep this in mind. 5000 milliseconds means I gave timeout of 5 seconds. If you want more things, you can mention it here. Like you can mention content type. But, my work will be done with this much. So here, const, const, this is our API, I give it the name API, or API instance, or Axios instance, whatever you want to give the name of the variable, you can give it. I keep the API simple here, so that it is easy for me to write, basically. I can simply work here simply API.get, API.post, this way. I don't have to do post, I have to do get. So, export, default, default API. So, I have exported here. Now, I don't need to import Axios here. I have made an instance. So, what will I do here? I will use the API here, I will import the API. So import API from dot dot slash dot dot slash. In config, x use. So from here you are getting the API. Now what I have to do here is API dot get. And here in the starting I had to write that HTTPS colon slash slash. newsapi.org slash version 2, you don't need to write that. Now I just need to write your main URL, which is everything, and if you are putting a query, then that. And along with that, the API key that we have given here, we will hide it a little so that it doesn't become public. Otherwise, if it becomes public, then your API key, which is very precious of API, can cost you a lot if someone touches the API key. Right now, you are using the free one. Assume you are Amazon, AWS, etc. And there you pay in dollars to AWS. Which you are using as a database. Or different services are provided to you. So whatever services you are using, you use through API. If someone gets hold of API, then he can take your entire cost. So, we have to hide the API and work on it. Now, how to do that? For that, I have not taught you yet. So, I will not tell you much about it now. Now, simply make a. env file here.. env. Where? In the root folder. I have made it in SRC. What is the mistake? Make it in the root folder, in my project. Okay? Look carefully. Don't make it in SRC by mistake. Maximum people do this. They make. env in SRC. We don't need to make it in SRC, we need to make it in the root folder. Where you have vit.config.js and where you have package.json, you need to make. env in the root folder. Now, in this. env, because we are using vit, I forgot how to use. env in vit. So, don't remember all this.. env in vit react. So, here you have you will get how to do it. So here VEET API URL is like this. Okay. So here your key is this. Where VEET you have to put this. In starting. If this will not happen then it will not be able to understand that you are using ENV here. Means who are you using? There are different ways in ENV. In React, what used to happen before, we used to make using Create React app. There we used to write differently. Here in VEET we have to write VEET in front. This is your prefix. You have to write this. Rest variable is just this much. API and this URL. so we will not write this, we will change it here, here we will call it Vite News API key, Vite is the prefix, it has to be applied, after that API key and here we will hide our API key So now no one will be able to see our API. How they will not be able to see and how we will push the environment variable while hosting the API. ENV means environment variable. How we will push it is a matter of discussion. We will not discuss it. For that, I will bring a separate lecture where I will tell you about ENV. How to put on the environment variable while hosting it. I will tell you all that there. And how it is very private. How you are securing the project. So that's all. Now here you just simply and make it. env in the root file. In the future, you should have this prefix with, later you can write it like this. And write it in the capital letter, it is a standard of API. And now we have to use it here. Okay, where? Here. So as a variable, like this. So, first of all, I will show you how to use CLG by commenting. So, as far as I remember, it is like this, meta.env, meta.env, it is meta.env, right? Import, import.meta.env. And then after that, this key comes. So, this is how it happens. See, if you don't remember, see, there is nothing to be ashamed of. Here you see how it is used. So, import.meta.env.yourvariablename. So you understood how to do it. import.meta.env. After that, your variable name will come here. So let's reload here. So look, you are getting API key. Now you have to use the same API key here. You have saved it in a separate private place. So you have to use it here. So I will use the template literal. Because I have to insert as a variable. So here. I have done this, so now our response will definitely come, why will it not come? Reload, so see you are getting data, now we do not fetch too much otherwise the limit is over, then I will be stuck in the middle, I will not be able to tell, so we have made the exeo instance, we have learned to fetch, we have hide the API key properly, now what to do, now we have to make a global state, so our configuration is still running, ok, there is no time in the project, there is time in the configuration, So here we will make pages, components and here you make context. And in context, which context will you make? For product, for news, you will make context. So here you give name, newscontext.jsx. Now I am giving jsx because I have to write jsx here. I want to create a provider in the same file. Also, I want to create context and use context in the same way. So I want to use hook here too. That's why I need JSX. I know. And I have told you all this properly. So here first of all, import createContext and use createContext to create the context. What is the name of the context? It is in three steps. The first step is to create the context. The second step is to provide all the components. Only then all the components will be able to use the state. And the third step is to use the context. So I have told you all this properly. If you want, I can leave it here. As a note, you will get this. So we have created the createContext and we will give the name of this context const newsContext. Now we have to provide this newsContext in all the components. So I will wrap the main component which is main.jsx in it and our work will be done. But for that we will have to make a provider first. So here we will make a const newsContext provider. which will be your component, news context provider. Here, the news context that we have made, look carefully, the news context that we have made, we are providing our state using this news context. In every component. Okay, how? So this will be our news context. News context. And whatever children will be coming here, like our main component will be main.jsx. If app.jsx will be there, your main component, then you will pass app.jsx here. which will be coming as a children. I just told you that as a children is coming here and here you can pass that children. So if you have wrapped main.jsx here, then you will get main.jsx here. If you have wrapped main.jsx here, that means you have wrapped your main component here, then you will get this state in all the components. You can use this state, whatever state you make here. So news, context, provider, you have not provided, you will use. provider and provide here. What to provide? Suppose I want to provide a value here, so now you can use this value in every component, in every page, anywhere in this VEET project. In any component. This is your global state. But we don't have to do this, we have to make a state. So, for now, let's check it. So, this is the news context provider. Now, to use it, we will make a different function. We will name it useNewsContext. We are making it like a hook. That's why I wrote use here. UseNewsContext. If I write use here, then I understand that it is of some hook type. So, this is our custom hook. We have made it our own. So, what will useNewsContext do? Basically, it will use this context. So here by using useContext, useContext has been imported. By using useContext, which context will we use? We will use the newsContext. That's it. So you have two things which are most important, newsContextProvider, which will provide your state in all the components, whatever state you will make, and then through useNewsContext, you will be able to use that context, you will be able to use that state, that's it. Now you can export these two here, export, NewsContextProvider and useNewsContext. So now the first thing we have to do is provide. So to provide we will come to main.jsx and here we will wrap it with NewsContextProvider. Our app. Okay. In main.jsx we will wrap our app. So, here we have wrapped the app. Basically, inside main.jsx, we have wrapped the app. So, inside the app, we have all the components. So, in all the components, you can use this state, which we have made inside the news context provider. Like, we have given value here, mkl. So, mkl, in every state, basically, you will be getting it in every component. Okay. Now, using this use news context, we can use it. So, I will use it and show you. For example, I want it in this news one. So, I will const state is equal to use news context. See this. Your import is done. And here you can see this state by doing CLG. You must be getting state. So what will happen in state also? MKL. See this MKL. So there is no problem. Now this global state which you have made, you can use it everywhere. So suppose I made this state in global state. I made this news state. We had this problem. So we made this news state here. At this place. Okay, and pay attention to make it in the same place because whatever hook you use, it returns and you use it inside your component in the middle here. So here we have made it and now we will pass these two here. Now how will we pass both? So we can't pass two, we can only pass one value. So we have an option here, make an object. We will make an object and pass both. So let's do one thing, let's make an object here. object here, let's make it here, which value and here news and along with that, we will also pass the news and you will know that our value is the same, so we can write in this way, like news is key and this news is coming in the value, so both are same here, news news, so we can write it in this way that the value is the same, alright, so we will pass this value here, we will pass this value here, okay, now Now we will get those two states in the state. Basically, to set and to get. Is it not getting? We have done something wrong. Here we have passed the value in this way. Everything is fine. And here use news context. And we have done something wrong. Use state is not defined. Okay, here use state is not defined. Use state. So now it has been defined. So let's reload. So look at this. This news one, which is our state, we can use it everywhere. Everywhere means everywhere. Wherever. Whether you want to use it in news or where else you want to use it. You want to use it, let's say, to set. You want to use it in navbar. You can use it in navbar. And if you want to fetch and set it in category, then you can use it here as well. And so there is no problem. Okay, why did you make it different to fetch? Why do we need to fetch in different places? Let's just do it in one place. Then we'll have to put await, async, trycatch everywhere. Better to do it in one place. Let's make a function here. FONS, FETCH, NEWS, NEWS, and in this we'll do all the work. Async, and here await. API. Is our API imported? What is this API? It is the instance of XEOS. So API.Gate and here we have this one. Do one thing. Cut this whole thing from here and paste it here. Okay. And uncomment this. All right. and here we will get the base URL from Meta.env.vit.api and from API.git we will get the base URL and we just have to work in the middle. In the middle, it can also be changed here. Suppose if I want to use fetch by giving a different query, then that query should come here. And if I want to fetch the top headline, then I want this function to fetch our top headline as well. Same function. Here you can make different ones as well. Here fetchEverything You can make a separate function and work separately for top headlines. But I think there is no need to work separately. You can also take the URL here. URL in this way. Sorry. You have to take the URL as a parameter. So whatever URL is coming, whatever URL is coming, you will put it here. That's it. Take this. You will put the URL. So whatever URL you will pass, it will fetch the data. It will give the response. You will return the response.data from here. Return. response dot data. That's it. That's it. Now you can use this fetch news everywhere. Okay? You don't need to make it again and again. And put this value below. So here we have made a state and also made a fetch function with which we will fetch. And also put try catch here. And you don't need to write try catch everywhere. Do you see how much fun our work has been done here? We have made a function in one place and our work is done. Console dot log error if error comes then error will be seen here rest will try to fetch the data if error comes then error will be consoled here so our site will not break completely robust site is made alright so state is made fetch news is made now let's come to news so what we have to do here remove this fetch news remove this remove all this remove all this we don't need it remove this API etc. useState etc. we have made state global alright so now let's bring state here const state is equal to useNewsContext and here let's see what we are getting in state let's do CLG state so here you will see that in state you are getting newsState along with a function fetchNews and along with a setNews so let's remove all three by restructuring news setNews and Fetch news. Write spelling carefully. If you are restructuring the object, spelling is very important here. So, we have taken out all three of them. And now we will do our work here. That's it. It is very simple. Fetch news. Okay. And in fetch news, if we don't pass the URL here, then error will come. It will come, right? Say it quickly. Error will come. See this. Because we have not passed the URL properly. And here we were taking the URL. So, we will give something here as default URL. In default URL, slash everything slash query is equal to Query is equal to India. So India's news by default will be fetched. Okay. Error is still coming. Error is coming. Okay. There will be a question mark here. I wrote it wrong. So now see error is not coming. That means our data is fetching properly. Okay. Can we see the data? Yes, we can see it. Here we have returned. So we have returned. So here we have cost data is equal to The data that will be coming to us from FetchNews, we can console that data and see. CLG data. Okay? Okay, promise is coming because here in FetchNews, we have basically put await, so it will return a promise. So promise will return, so again we have to make a function here. Have you heard the name of the immediately invoked function? You must have heard it, definitely. I have told you. So in this way, you have to put two parentheses and make a function in it. So this function will also be executed. There is no need to call separately. Okay? If you are new to this, that means you have not read the JavaScript properly. There was a lecture on functions, I have discussed all these functions in the JavaScript in an hour. So, I have made this immediately invoked function expression. Why have I made it? Because I can't directly use the weight of async here. If I put async here, then this is a syntax mistake. Async cannot be used here. So, I have made an immediately invoked function expression here. If you feel that you can put the weight of async here, then you can't. See, I wrote async and here I wrote await, but No, it won't work. There will be an error. Look, there's an error. In useEffect, this error is telling us that you can't work like this. So here you can make a function separately or you can use the function expression here immediately. This is our function and this is how we called it here. Alright. And here await and we will make this async. Very good. So here you can see what data is coming. So here you can see the data and you have the status, total results and articles in the data. So we don't have to make the pagination, so we will set the direct articles. By using setNews, we will set data.articles in it. Now can we see the news? Definitely we can see it. So whenever there is any change in the state, our re-render trigger will happen and we will be able to see the news. Let's reload. As soon as the news load, you will get 100 news. Wow! Great! Great! Great! Great! Great! Great! Great! Great! Great! Great! Great! Great! Great! Great! Great! Great! Great! Great! Great! update that main state, which was the state of news. And here our render will be done automatically. We don't need to make any component separately to render. Render is our news page. News page is doing the work of render. So, whatever news will happen in news, it will render. Whether we choose sport in category, then we will fetch the sport data, it will render. Simple. Very simple. And it is fetching on loading in the starting. Load data on initial render. It is fetching this data when it is loading for the first time. We will set a new on its button click and it will be rendered here. Very good. Very good. So we also list this news here. News.map and if there is a higher order function, then we will return it in this way and our work will be done with one news card. Remove all this. Alright. And here you must be getting news details. Okay. And here you pass details is equal to news details. Okay. Here we have given details. So here as a props we will receive details. We have sent the details props in the news card. We are receiving here and you can see what is coming in the details after doing CLG. Details. Great. So you see what is coming in the details here. So you have author coming, content, description, publish that, source. And I had shown you all this in the documentation as well. So it's not a big deal here. And here the key error will be coming. So here in the key, you can use index because ID etc. is not given. So we will put index in the key. Okay. and we will also use the details here. So in this src, we have to put the image. From where will we get the image? So URL to image. There are two URLs here. The first URL is the URL of your entire site. That means where the news is listed, that is the URL of the site. Like yahoo.com. And the second URL to image is the URL of the image. So we have to use the URL to image here. URL to image. Okay. So, look at this. You should have got the image. But, it didn't come. I don't know why. Okay. Details.url to image. Details.url to image. So, look at this. It has come. And, if your site doesn't come fast, for this, you can also do optional chaining carefully. Okay. Here also, you can do optional. Here, there is no need. Because, initially, we have given an array. So, if the array is empty, then, nothing will be rendered. And, if it is filled, then, it will be rendered. So, here, keep doing optional chaining. Now, like the title. Title. So, here, details, optional chaining, title. Okay. Rest, the details will be coming. Because, if it is being listed here, that means, the details will be coming. So, there is no need to do optional chaining. But, still, it is good. So, here, the title is coming. And, let's show the description here. Details.description. Details.description. Okay. It is description, right? Yes, it is description. Description. What else can you show? Nothing else. And on clicking the button, you can redirect to another window. You can do window.open. And here details.url. Right? These are all simple things. Window.open. We saw that the whole site will be opened from details.url. So we redirected. We opened another window of that site. So as soon as we click on this buy now button. So buy now or not. Here. Read more should be. Okay. Read more. Here we are clicking on read more. So this is coming on that site. Okay, great. So this is working properly for us. And this console job we have done, you can remove it from here. Now we don't need it. So we have properly listed the news. But it's looking a little wrong. News is looking a little wrong. And it is also consoled here. So remove this too. It is properly set in the state. I found out. This is not looking good because first of all, you have to fix two lines here that it should not look more than two lines. So here we will put the line clamp 2 and in the description we will put the line clamp 3. Last name line clamp 3. Okay. It will not look more than 3. And if you want to see in detail, then click on read more and go and see in detail what the problem is. So in the button, here we will give a little margin top of 4 so that it comes down a little. Now it is looking good. Isn't it? It looks lovely. And why do I feel a little bit wrong in the button? Here is this button and here we have given this button. So how is it? How is it? Come to Tailwind and search card. I also did that from Tailwind. I don't know. You will have to see. Card. So this is the button. Did we take any other card? Okay, we have installed this card. So let's see what class name it is using. Okay, this is badge. Badge, badge, outline. So let's take this class name. Let's remove the button class name. Remove button, button, primary. And use badge, badge, outline. So this is something like this. Okay. And, and, and, and, and, and, and, and, and. If I give it btn, then it will become like a button. And if I remove badge. Aha, now it's okay. So, I have mixed both of them. So, you can see the badge outline and the button. So, the shape of the button is the same as the badge outline. So, the shape of the button is the same as the badge outline. So, the shape of the button is the same as the badge outline. So, the shape of the button is the same as the badge outline. So, the shape of the button is the same as the badge outline. So, the shape of the button is the same as the badge outline. So, the shape of the button is the same as the badge outline. So, the shape of the button is the same as the badge outline. If the heading is equal to the sequence, it looks good. See, if the image is a little less here, it looks like this. So we will correct the image a little. We will give the class name here. And here we choose aspect video. So it will come in the shape of a little video. But it's a little sticky. So for that, you can cover aspect or content. Object cover. If you cover it, it will be properly covered inside it. But the image will be cut a little. So if you do content, then your content will come in this way. The whole image will come, but it can be a little empty. If the image is a little long, then this side will look empty. And if the image is sticky, then it will become a little space on this side. And if it is flat, then it will become a little space on the top. But the whole thing will be contained. As you can see, space has become up and down here. And look, this is a little long. A little space has been made here and there, but the whole fit is coming, isn't it? And the aspect is video and if the image is not somewhere, then see if there is no image somewhere. As if there is no image here, then this heading has gone up. So you can do one thing, if you keep its width full, then the aspect ratio will be maintained. If the width is full, then it will take the height according to itself because the aspect video is given. What does video mean? Video is of rectangular shape. If I have filled the width, then it has to be rectangular. If there is width, then there will be height. Because I have given aspect as video. If there is no image, then it will be like this. And it is possible that there is no image URL in some. This can also happen. The data that is coming, it is possible that there is no image to URL in some. This. There is no URL to image. So we will not render what is not there. So we will do one thing here. We will put a condition here. news details dot news details dot url to image if it is not there if it is not there then return null don't return anything and if it is an image then return this so see there was no image in it ok so without image you won't be able to see it means you can show it if you want to show the image which is not there then there is no issue you can show it but I removed it Okay. So, some image is coming. And it is possible that the image has a URL, but the image is not available. This can also happen. So, we can't do anything for that. So, it will look like that. So, proper. This is done. Now, what to do here? Now, here we have to do the category work. So, let's do the category work too. So, now there is no issue. News is being rendered. We just have to fetch in the category. Okay. We don't have to do much in the category. We just have to fetch according to our logic. So, here on the button, we will put onclick and handle click and name it handle click function so const handle click that's it so here we have to handle handle click and here whatever category will be there that category will be coming here and according to that category we will be fetching data so to fetch data again we have to do the same thing here, we have to do the same thing here, but here we have to give the URL while fetching, here we were not giving the URL, so by default our URL, by default our URL Wait a minute, come to the use news context. By default, our URL was slash everything and query India. So if we want the news one in the category, then we will have to pass news in the query in this way. Slash everything and in the query, if you want the sports one, then you have to pass sports in this way. If you want science, then you have to pass science. If you want business, then you have to pass business. So we will do it. There is no issue. A sing. Okay, wait. So whenever we click, the data will be fetched here. And we will set the article in set news. Okay, now we have not taken the state here. Use news context. And here set news. Set news and fetch news. Okay. So these two have come to you. So fetch from fetch and set from set news. And render is happening in the same component. Great. Great, great, great, great. Okay, so let's click the handle once and see. So I will reload now. Right now, this whole news is coming, whatever it is. So as soon as I click on entertainment. So nothing happened. Nothing happened. We have put the handle click here on click. So this handle should be clicked on button click. And on handle click, we should have a sports news page. By law. Right? CLG data. Control shift I. Reload. So, as soon as I clicked on science, some error came. We have made some mistake. Slash, again we have put slash. Here there is a question mark for query. Okay, let's reload. So, as soon as I clicked on technology, so there is still some problem. Cannot read properties of undefined. Bad request, it is telling. Exuse error. So... Let's come to network time and check what's going on. What's the API calling? So, in general, the API that's being called is newsapi.org slash version2 everything. In the query, in the query, in the query, a little bit, something. Okay, this, this, this, what's this? We didn't have to put this. We have put this inverted comma. So, it's fine now. It should come now. As soon as we click on any of them, our sports will be fetched. Because we have written sports here. So look, sports is fetched. All the news related to sports has come. It has changed. Very good. So our click is working. Let's come back to the console for now. So our click is working. So EA is happy to know that our click is working. But one more thing we need is that if there is a business here, then the business should be fetched. So we will do one thing. For this, we will pass a value prop in the button. and we will put the same category in the value so if it is business then category will be business and if it is sports then it will be sports and we will remove this value with the help of function with the help of event object you know all this so here we will remove the value from e and e.target.value const category is equal to e.target.value E.target.value and as soon as we click, our direct will be fetched here. However, you can also make a state to save it, which category is selected on the handle click. So for this, you can also make a state, but it will happen even if you don't make it. However, if you make a state, then we can call it a controlled component. So our work is going on in a controlled way. But okay, your work will work here too. The category is here, you put this category here. So you have to use the template literally for that. So we will use the template literal in this way. And why is there an error here? Okay, it doesn't look like curly braces here. So here we will pass our category. Alright. So as soon as we click the handle, we have put this category in the value. So if it is sports, then our sports will come in e.target.value. So here will be a query related to sports and there will be a data fetch related to sports. Science related data will be fetched. That's it. Data will be fetched and data will be set. Set will trigger the read-under and the whole news will come back. Let's reload. Now see, generally any news is coming. India's news is coming. Click on technology. The whole news related to technology has come. Click on exports. So the whole sports related news is coming. But there is a little glitch, there is no loading here. So loading will also have to be applied. So loading will be applied at the end. For now, let's make the search one too. So the search one will look very simple to you. Same work has to be done. Same work has to be done. Okay, debouncing also has to be applied, right? Otherwise, we will keep typing, the search will keep happening. I mean, a lot of API will be hit then. So debouncing is an important work there for now. So in component, do it inside the navbar. Or make a separate component for search. There is no need to make it separately. Let's do it in this. It is a small component. How many lines does it have? It has a code of 28 lines. Okay. It has a code of 28 lines. It is not too big. Let's do it in this. So here const search value comma set search set search value. I have written it correctly, right? Spelling. See the spelling carefully. Set search value is equal to use state And it will remain empty in starting. And in input, onClick, E, and setSearchValue, E.target, target.value, we will set the value. Okay? So as we type, I will be getting the search value. If you want, you can do CLG, useEffect. And whenever the search value changes, we have to call API, right? So here the search value should be changed to run the use effect. Let's do CLG first of all, the search value that what search value is coming to us. And at the same time, put the value here. Search value so that it becomes a controlled component. As soon as the value changes, the value will be fit here. Okay, so let's come here, reload and provide a value prop to a form filled without an on change. Okay, we didn't give an on change. Ok, it gave onclick, so sorry, onchange. Ok, now let's reload. So as soon as you type something here, minus, so here minus is coming to you. Now as soon as minus comes, you have to fetch data according to it. So similar to this, copy from here and copy and come to the navbar and come to the navbar and remove this from here and you have to do this work here. Ok, you don't have to put category here, you have to put search value in the query. Ok, search value, that's it. and your work is done. Now in useEffect, again, how will you work as a sync? So here you have to immediately make an invoke function. Right? So here you can work like this. Async and await. Okay, so whenever the search value changes, it will query according to that search value and it will fetch data and set the data. Okay, but the problem is, the problem is, reload it. Here, fetch news is not defined. Okay, here we have not imported context. Is equal to use news context. Alright. And here we will get set news and along with that fetch news. Okay. So, there should be no error now. Proper. Okay. Is data fetching happening? Oh, I am so sorry. Here, Hmm. Reload is also fetching data. This is also a problem. And on reload, the search value is empty. Okay. We don't have to fetch data in the starting. We have to fetch data when we type. So. So. So. So. So. So. So. So. So. So. So. So. So. So. So. So. So. So. So. So. So. So. So. So. So. So. So. So, directly here in onChange, this thing we have set separately, setSearchValue, directly here, make a function of searchNews and do the work. Simple. const searchNews, that's it. And this whole work that we have done here, you do this work here. Okay? Remove this. There is no need for state either. We are spreading useless garbage. So, we have done search news in onChange. In search news, you can take out e.target.value from e. Whatever is being typed, you will get the value. const searchValue.value is equal to e.target.value. That's it. And make it async here. And your work is done. So, whenever you type something, you will have a value. And if there is a value, then it will be searching for that value. And if the value is not there, if not of search value, then return it here. However, what we did in the use effect, if we had written only this condition in the use effect, if there is no search value, then if we don't have to fetch, then our work would have been done. but then we deleted it and used this logic, I don't know why. So even there if you do this work, the use effect that you made earlier, even there if you put this much condition, then also initially it will not render because there will be no value, then also it will render. So you can put this condition, although this is also fine, we will not have to make a separate state. Okay, this will also work for us. But then if we want to reset that on fetching, no, we don't want to reset, right? Reload, I am thinking of handling it like a form. I can't do that. So if I search here, see how many times the API is called. Let's go to the network tab and select the fetch one. And here it is. Now it has been initially reloaded once. If I search for Tesla, the API will be called once on T and the API will be called five times on ESL. Tesla. Look at this. While it should have been searched only once, the API was called five times. This is not right. The API should not have been called 5 times. It should not have been done like this. I want this API to be called when the type stops. So how can we do this? To do this, it is easier than useEffects. De-bouncing. But let's put it in this if we have made a function. So we have to do de-bouncing. So how can we do de-bouncing? So we will make a timer basically. See, what does de-bouncing mean? Suppose you want to search after a minute of stop. How many minutes? After a minute. Search after a minute. Alright. Search after a minute. So you have typed something. A. You have typed A. You have typed A. So you will set timeout. Set timeout of a minute. Okay. So now it will search after a minute. What will it search? Whatever you have to search, it will search after 1 minute. Like you have typed A, it will search after 1 minute. Okay. But if before 1 minute, before 1 minute, I have typed something else, B2, then again, what will you do? You will set timeout and then you will say, search after 1 minute. So, this first one, 1 minute, and this one, 1 minute, so it will search after 2 minutes, right? After 1 minute, it will search only 2 times. So, you have to cancel as well. This old one, cancel it here. Okay. This. So cancel the old one. As soon as you type the second letter, you will clear the old timeout. New timeout will start in a minute. Then as soon as you enter the third letter, you will put set timeout here. Set timeout of a minute. And you will clear the old time. So you have to do this. Okay. And when you type stop like this, after a minute of it, you will be searching. I have said more than 1 minute. We will use 500 milliseconds. But it is fine. I told you to explain. Otherwise, 500 milliseconds, as soon as you type stop, it happens immediately. Alright. So how can we do it here? So we have to work in this. So const timer name is given. And in this way set timeout. And it will suggest the entire VS code. And assume that we will use 1 second here. 1000 milliseconds means One second. Okay. So, I have made a timer of one second here. And we will put it inside this. Okay. Alright. So, what will happen now? Whenever we type something, and await is here, so async is made to this. Now, we have to make async to this. Here. This async. Okay. So, we have made this timer. Okay. Now, what to do? So, we have made the timer. So, this thousand second, sorry, thousand second is too much. One second, means thousand millisecond. after 1000 milliseconds. Whenever I type, listen carefully, I typed A, I typed A, so after 1 second, this search process will start. But if I type B in that 1 second, what did I say? Wait a minute. If I type A, then after 1 second, this search process will start. But if I type B in 1 second, then? After 1 second, it will again start the search. We haven't cancelled the old timer. So, it will search again twice. Let me show you. Let me reload. In the network tab, I have typed ab. Even though it happened after 1 second, but it happened after 2 times. Because we haven't cancelled the previous time. I want that if I type A on A, then the search will happen after 1 second. But if I click any button again within 1 second, then the old timer will be cancelled here. And only this timer will remain and wait for 1 second. Means when I stop at the last, then the search will happen after 1 second. So how will we do that? Whenever we are searching, we have to cancel this timer. Clear timeout. We will use clear timeout to clear this timer. We have made the timer below, we are making it clear above. What is this? So we will definitely have to make the timer outside. So let's make the timer here. And here we will set timeout inside the timer. And whenever we will search, the old timer will be cleared and a new timer will be installed. Clear? We made a timer outside. Assume that we are typing something for the first time. So, when typing, there is no clear timeout. There is nothing in the timer. The timer is null here. There is nothing in the timer. So, what is the clear timeout? There is nothing in the timer. A new timer is set for 1 second. Assume that I typed something again within 1 second. So, the old timer will be cleared here. A new timer will come again for 1 second. Okay? So, now if I here, now if I here, assume, search for A, B. Searched only once. If I search for Tesla here, it was called only once. You can see here that the API was hit only once. So this is called debouncing. You can make a separate function for debouncing by using bind and arguments. But here this method is very simple, it is beautiful, you must have understood easily how we applied debouncing here. So this is our apply. If you want, you can increase the time. You can do 1000, not 1000, you can do 2000. You can also do 500 milliseconds. If you want the user to type a little faster, you think 500 milliseconds is good. Rest 1 second is also fine. If you want to save more cost, then alright. So this is done. Now the last thing left is the loader. Everything is done. We are clicking on technology. Technology related news page. But it looks like a glitch. Reload is not happening in between. Here nothing like a loader is coming. So let's put a loader too. Why keep a loader in the last? So I will search tailwind loader. Tailwind CSS loader. And you get a good loader on the universe site. So come to the universe site. Universe.io And here CSS loader is also there. Tailwind loader is also there. So click on tailwind. Otherwise you will get CSS loader. You can also use the CSS one, you can't use it in React. So I need a Tailwind loader, so I clicked on the Tailwind one and see which loader is needed. So I had installed one loader, which I had installed in this application. So I will use the same loader here. Okay, so I will copy it from here and in the component loader.jsx rafce and here we have our loader. Great. Okay. And this comment is creating this problem. So this is our loader. And class is written everywhere. Class name is used here. So class is equal to. Replace it with class name is equal to. Otherwise it will give warning error. Class name is equal to. So we have made loader properly. Now let's install loader and see how it looks. So where to install loader? In news component. And install it here. Yes, install it here. We will install it here. Can we install it outside here? Can we put a loader here too? No, no, we can't put it here. Okay, why can't we put it here? I said we can't put a loader here. If I make a loading state here. Let's make it. We will make a loading state here. Where is our context? Yes, here it is. I thought it disappeared. So this context here will make a set loading and loading state. Const. loading comma set loading or is equal to use state or by default let it be false. So now because we have done all the work with one single function, then we have to do loading, set loading in just one function. Otherwise, we would have to do it everywhere. So here we will do set loading in starting. True. And as soon as try catch will happen, let's say data fetch is done, whether it is done or not, data fetch is done or error is done, either of the two, we have to do loading false. So set loading, sorry, set loading, false. So as soon as this function call will be fetch news, loading will be true and data will wait for data here. And if data comes, then also loading will be false. And if data does not come, error comes, then also loading will be false. Okay, Great. So this loading state, let's say I asked you a question, in app.jsx, can we conditionally load the loading state here? If loading is true, then show loading, otherwise show news. Can we do it here? It is a very important question. Okay? Let's say in the interview, I am asking you, this is the news component, you see carefully, we are rendering all the news here, API is called here, and let me show you the context here that this fetch news which we have used in the news, remove all the categories in the news. Let the app remain. So the question is, can we put a loader here using the loading state and if the loader is not true, then what news component, we can show the condition here. This is your question, that is, here we will take the loading state in this way. And if the loading is true, then we will show the loader in this way. And if the loading is false, then we will show the news component here. So this is a simple, I mean, what's the matter with this? We can do this, we do this. Think carefully and say, can we do this? If you ask a question, then there will definitely be some logic behind it. So here is the news component and you can see the news context carefully here. There is a loader here. which is by default false. Loading is true when fetching. And here at the end loading is false. And one mistake is here that if you look here carefully, then if data is fetched here, then data will be returned. So loading will never be false. Loading will continue. So this is the problem. So we have to false loading here before returning. If data comes, then first false loading, then return data. And at the same time, it will also have to be done in catch. If data does not come, if there is some error, then also false loading. So this error is fixed and we are not using the loading state either. If we pass the loading to the value, then only we can use the loading. So here we have fixed the problem. So the question is still the same that we are doing all these things in the app that if the loading is true, then we have to show the loader, otherwise we have to show the news component. So is this right? And in the news, we are using the use effect here and fetching data. So if you ask the question, then something or the other will be twisted in it, something or the other will be a trick in it. If you are saying that loading is true, then the loader will not be visible, then the news will be visible. What is the problem in this? So you are thinking absolutely wrong. You are stuck here. Here it will get stuck in the loop. Think carefully. Loading by default is false. The news component will run. The news component will run, then the use effect will run. The use effect will run, then the data will be fetched here. Data will be fetched. Data will be fetched. So here you have that loading will be true. Now, if loading will be true, then news component will be unmounted. Data is also being fetched. News component again will be unmounted. News component came, but unmounted and loading will be done again. Why? Because loading is true, if data is being fetched. Okay. And if the data is fetched, then the set loading will be false. After being false, this component will be mounted again. Now if it is mounted, then the use effect will run again, the data will fetch again, the set loading will be true, the loading will be true, the loader will be visible. Now the loader will be visible, this component has been unmounted, now after the data is fetched, the loading will be false again, after being false, the news component will be visible again. And the news component will be visible, meaning the use effect will load again in the news component, the use effect will work again, the fetch news will work again, the data will start fetching again. Loading will be true again. Loader will start showing. It will get stuck in the loop. It will be mounted or unmounted. It will be mounted or unmounted. UseEffect will run again and again. Loading will be true or false. It will be true or false. It will be true or false. It will keep running. It will keep running. If you don't believe, then come and see. So here, first of all, you have to bring loading state from useNewsContext. UseNewsContext. Okay. And along with that, you have to import the loader here. Import. loader from dot slash components slash loader and come here quickly and see the news is fetching, it is coming, it is coming, it is coming, it is coming and see, it is stuck, it is stuck, it is stuck, the component is coming, where is the network type, it is in the network, see how much API is being called and our API is getting hit, it will end quickly, comment it, Otherwise, I won't be able to tell you further. So, it got stuck in the loop like this. Loading is true, false, mount and unmount. So, you have to try it once by drawing it in your mind. So, we won't do it like this. Definitely. This is a wrong way. So, what will we do? We will let the news component be mounted. After mounting, we will do our work in the news component. Here we will take the loading state. Okay. And use effect will run. Data will be fetched properly. After fetching, loading will be true. Loading will be true. So, here We will check if the loading is true. If the loading is true, then return loader. Okay? Loader. And if the loading is false, then we will return this component. Component will not be mounted again. So useEffect will not run again. Because we have run it only once on one load. Okay. So will it work correctly now? Exactly. Import. And what did we have to import? Loader from dot dot slash component slash loader. Alright. Come here, reload. Now what's the problem? See here. News is not defined. What? News is not defined. How can this be? App.jsx line number 14. App.jsx line number 14. We have also removed the news one here. Import by mistake. Okay, so now the news is defined, right? News. Okay, look at this. Loader came. Loaded. Loaded. Component came. It's not calling again and again. You can also come to the network tab and see. It will call once again. We will go to sports. It called and came. Loader came. It went. Component uploaded properly. Okay, pass your class name in the loader. Otherwise, it looks a little dirty. Class name. And here you use the class name of the template literal quickly. Fattah Fatt. Class name. Okay. And come here. Give it a class name. What class name do you want to give? So, give margin auto. And give bg red 500. See how much background it contains. So, okay. So, this is in the middle. And now you can remove background red. This is in the middle. Give padding y a little. Give 20-30. Isn't it 30 padding? It must be 20. Is it 32? Yes, it is. Okay, now see, let's reload. Hmm, this is wrong. I gave padding, so actually in the loader, see this was width 32, height 32. I gave padding, so the loader was pulled a little. So don't give class name here. Do one thing, move from here. Make another div here. Do this work in that div. last name and this class name in this way and put it in the last here ok done great format ok and this red red line sorry why is this green green line coming So it is saying that we can write it as bg-linear2 but I don't feel like writing it. Okay, so now let's reload. So now it is coming to the side. Because it seems to be taking the full width. bg-red500, see how much width it is taking. It is taking the full width, right? So do one thing. Not the full width, but the width-fit content. Take the width as much as the content is. Now it is fine. And remove this background from here. So now see this loader. What is loader? Loader, loader, loader. See this loader. It looks proper. Reload. And padding is a little more. Give a padding of 24. It will look good. Now you can see according to yourself. So this will look like this at 100%. And in network tab you come and check. Unnecessary API is not hitting. See clicked on technology. Loaded. Data related to technology came. And data related to this is coming. And padding wise padding bottom se thoda kam aara hai na y se to thiki aara hai padding y se to itna thiki hai margin bottom se de do thoda sa 6 ka to 10 ka le lo re baba tum 32 ka le lo ab thik hai Now it's looking good. So if we do it on health, then the news of health is coming. If we do it on science, then the news of science is coming. And see, three API calls have been made here. And now if we search Tesla here, then only one API will be called after a second. Wow! Wow! So we have worked properly here. And your one task here is to click on it. A drawer should come from the side and all the top headlines should be seen in it. Okay. All the top news should be seen. Top headlines. So you will make it by yourself. And the rest of the pagination will be discussed in the next lecture. In the next lecture we will discuss pagination and environment variables. I don't know why. Basically, the concept of pagination is completely different. Although, JavaScript is a part of it, I believe. Logic-wise, there is a lot of work there. React has nothing to do with it. But okay, if you know how to make pagination properly, in every project, if you are making a big project, e.com or any other, if you are making a course selling educational app, there is a need for pagination everywhere. At one time, you don't show all the millions of data. page by page. If you are making any website, then pagination will be needed. So pagination is also important. So this has become your proper, UI has also become proper. If you want, you can check if it is responsive or not. Which tab was open here? Daisy UI. So close this and don't close this. So it has become exactly the same. And change it a little bit here in the wrapper. Instead of 280, I had put 70rem, now let's put 80rem and see how it looks. 80rem was perfect. So how much do we call 80rem? 7xl. So here, give 7xl. See, I changed one place in wrapper, now it's completely spread. So this is the advantage of wrapper. Good code is written like this. Although there are other things that I can't do right now. I haven't told you all those things. I haven't taught you all those things. If you do, then a lot of things can happen. If you make a to-do, then to-do is not as simple as you think. To-do is a very complex project in itself. I am talking only about to-do. It is a very complex project in itself. If you look at Instagram, then it is to-do. Facebook is also to-do. Create, read, update, delete, you do it in all. In GitHub also, you create, read, update, delete. GitHub is also a to-do. In that, you send a lot of data, handle a lot of data, get a lot of data. So, everything is to-do. So, to-do is also a very complex project in itself. If you don't know, then find out. To-do can be made to this level, in which your entire react will be covered. Okay. State management will be covered. You can use local storage, but working with API will be more fun. Everything will be covered. Everything. The whole react with one todo. We will do that too. So it depends on what level you are taking todo to. That create, read, update, delete means it is done easily. To what level are you going, to what level are you optimizing? There are many things in todo, not one or two things. Like this project, this project could have been made in a very simple way. But what I did, made configuration, created instance, then put it in environment variable. then managed the context properly, in that, the way it has been done, if you understand it properly, you can make your own freelancing project in the future. Okay, the way I am taking it, just keep walking. It will be fun. So, our project is done, if something is left, then that is your task, you have to do it. Okay, like if you put footer milling according to you, and rest of it, I think it is fine. And then we will meet in the next lecture. Till then, bye-bye.