Podcast Lookup

Master React JS Components | Everything You Need to Know About React Components

ReactJS Developers Podcast

  • December 3, 2026
  • 1 h 1 min
  • Episode 31
Episode page
About this episodeReact components are the foundation of every React application. They allow developers to break complex user interfaces into smaller…
React components are the foundation of every React application. They allow developers to break complex user interfaces into smaller, reusable, and manageable pieces.In this episode, you'll explore the fundamentals of React components and understand how they work together to build dynamic web applications. From creating functional components to understanding props, component composition, and reusability, this tutorial will strengthen your understanding of React's component-based architecture.Whether you're just starting with React or looking to improve your development skills, this episode will help you write cleaner, more organised, and maintainable React code.What You'll Learn
  • Understanding React components and why they are important.

  • How component-based architecture works.

  • Creating functional components in React JS.

  • Understanding JSX and how components return UI.

  • Importing and exporting React components.

  • Understanding reusable components.

  • Passing data between components using props.

  • Understanding parent and child components.

  • Component composition and nesting.

  • Organising components within a React project.

  • Best practices for building maintainable React applications.

Who Should Watch?
  • Beginners learning React JS.

  • JavaScript developers transitioning to React.

  • Frontend developers improving their component architecture skills.

  • Students learning modern frontend development.

  • Developers building scalable and reusable React applications.

Transcript

From the publisher

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

Master React JS Components | Everything You Need to Know About React Components

00:00—
  1. Speaker 1

    So, we are going according to the roadmap of our react. I have given you a very nice detailed roadmap in the third or fourth lecture of the playlist. I believe you have seen it. I have also given this link and it was also in the normal PDF format. So, we are going according to this roadmap. Okay, now in this, first of all, I told you to see this JS portion, you have seen it, so this portion is complete. We are in phase 2 now, look carefully, we are in phase 2, many people think that we are going in detail, we are not going, or where is it in basic, how is it, so once you focus on the roadmap, then you will know. In phase 2, we have seen how to install CLI tool, create react app and folder structure. Now we are in components. I have not given you the detail idea of components. I have told you JSX first. I have told you about JSX because when we will see components, there will be use of JSX. Now I will explain you about JSX, before that I have explained you about JSX. Now we are going to go in depth in components. In this lecture we are going to go in depth in components. You will get the idea of props, states and to a great extent you will get the idea of data flow. Only idea will be used. Okay, going in depth is remaining. You will go in states, here you are seeing the life cycle, it is the part of phase 3. So, we have to go in depth. Now, I am telling you that we have already gone in depth in JSX. We have also gone behind the scene. Today, we are going to discuss about components properly. Although, I have told you almost everything about basic. I have told you about components, states, props, data flow, hooks, styling, event handling to a great extent. So, I have told you a lot of basic things if you talk about it. But if we want to go in detail, we have already gone to JSX. Now we will discuss about the components in detail, how to manage the components, what is its internal memory, what are the types of components, all those things. And props, states, data flow, the idea will be taken. Rest, videos will be coming in detail. So don't think that so many components are over now. Then we will go to hooks, styling, etc. And then life cycle, etc. is the third phase part. Okay. So let's go ahead, I have cleared you so that you don't get any confusion that something is missing or something like that. Very good. So we come to the code base quickly. This is our code, I have cleaned it completely. See this, this is the wheat folder and before that we have done all these things. So I have already installed a project of wheat, you can also do it. And in SRC, I am also in app.jsx and I have already cleaned it completely. You know all these things. I will also run it. How to run it? Tell me quickly. npm run dev. So, this project is run. No, it is not. Ok. First, go to the wheat folder. See, we are not in the wheat folder. We are in the react folder. This is the wheat folder in react. So, cd wheat. And then we will do npm run dev. And this project will start running. So, here this project is run. Nothing is visible. This is because we have not given anything here. So, we will give hello. Hello react pay react. Alright. Now we come to our notes. So what is components? You have already got the idea about components. What is a reusable piece of UI? But let's try to understand it a little better. So that you can get more detailed understanding. Components is a reusable piece of UI, not a function. Functions and components have a major difference. I will tell you that later. Components is a reusable piece of UI, building blocks of every React app, can be combined to form a complex interface. You must have understood some things, because you have read a lot of things. If you haven't understood, then I will tell you practical examples in depth. Now, in this, we can talk about components. First of all, suppose this is your first component. This is a complete component. Listen carefully, what I am saying. This is a complete component. Then you have this second component. And this is the third component. And this is the fourth component. You have made this component. And what is the component? Listen to me carefully. Listen carefully. Component is a reusable piece of UI. User Interface. The things that you can see, like this, you can see this type of UI. So, this type of one UI, we are calling it as one component. This second UI, second design, we are calling it as second component. This third type of UI, we are calling it as third component. This fourth type of UI, we are calling it as fourth component. Okay, that's it for now. So this is one component, second component, third component and fourth component. Now we can combine this component in this way. We can make a user interface by combining the components. We have attached the first component here. First of all, we have attached the second component here. Then we have used the third component twice here and here. We have used it only twice. We have made a component only once. We have made it only once. We have used it twice. So this is also a benefit of the component that you make it once and use it multiple times. The principle of don't repeat yourself is properly followed here. This is the principle of programming. Don't repeat yourself. If you don't have this component, then you have to write this code again and again. Once you write a code here, then you write a code here, then your UI is made. But it's not like that. You have made a component, you are using it here, you are using it here. Similarly, you have made this component, you are using it here, if it will be used in the future, then we will use it there too. Then you are using this component here and the second time you are using it here. You are just using it. You don't have to write the code again. You are just using it. Then the fourth component, you are using it here and here and here. You see, once you have made a piece of UI. What am I saying? A piece of UI. User interface. A piece of UI. You have made a piece of UI which is visible. You are using it again and again. So this piece of UI is your component. Alright. But this is not the only one component. The whole thing you have created has also become a component. The component can be small and can also be a big component. Now let's come to a practical example. It is not that we will just see this box. So here you must be able to see a lot of things. If you look carefully, you can see this portion here. Can you see it? What can you see? You can see a girl. If you look at the whole picture, you can see a girl. Then you can see the rating, the title, the description, and the price. Look at this one carefully, there is only this much in it, then look at this one carefully, there is only this much in it, there is a photo, then there is a rating, there is a title, there is a description, then there is a price. Then look at this one carefully, there is a photo, there is a rating, there is a title, there is a description, there is a price. Does everything look the same? If the photos are not different, then everything is the same UI. I can say that this is a component, we are using this component here also and changing the data. I can say that we are using this component here also and changing the data. The UI is the same, the component is a piece of UI. So the UI is the same, just changing the data. So is this also a sub-component? Definitely. We have made one component somewhere, we are using it again and again by changing the data. Ok, so we use such a component that we have made it once and we are changing the data. We don't have to define the UI again and again. Yes, exactly. Making a UI is not very complex, but it can be a complex UI. Like this is a small card. Ok, think about it yourself. You have to write this card again and again. Once you are making the code by writing here, once you are making the code by writing here, once you are making the code by writing here. How long would the code be? Ok. You have created a component and the same code is written here. You are just changing the data and all your products are listed here. Then it is possible that this whole category section is your component. In that too, it is possible that you have made a small tick box. This is your component and you are using it again and again. See, everything is the same. It is just a data change. It has been ticked in this. It has not been in this. Then it is possible that this is a complete component and this small one is also a component. The same small one is also being used here and here. And these small ones have become a whole big component. This is also a complete big component. This is also a complete component. Then after that, this new bar that you are seeing. Wait a minute. Oh man, what happens? Don't you want scale? It seems that something is wrong. Something is wrong. Why is it not working? Wait a minute. What is the problem? I have to fix it. Hmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm It is definitely a good thing. So let's move ahead. I will fix this paint dye problem first. Otherwise, there will be some irritation in teaching. Wait a minute, give me some time. So now it is working perfectly. this one example. After this, we have one more example. See this carefully, this UI will also be repeated three times here. UI is being repeated, that means it is a single component. We are using the component again by changing the data. Ok, here also it can be a component, as you can see, we can increase or decrease the range by moving. This can also be a complete component, this can also be a complete component, then this search bar is a complete component, then this is a complete combined component. I don't know again and again, it gets selected, that's why there is a problem. Ok, this is a complete component, this is a complete component, which you can see, this is a component, there can be a single component in it. In this way you can have small components and you can make a big UI by combining the components. The benefit will be that you can use the small components anywhere. Make the components and use them wherever you need them. You don't have to repeat the code again and again. If you feel that you have to repeat the code again and again, it is better to make a component and use the component. Now let's see how to do it. Then we will see the types of components. Component is a reusable piece of UI. We have to focus on UI item. This is the major difference between function and component. We do not define UI in function, we define reusable piece of UI in component. We can make complex interface by combining building blocks of every react app. How? Let's see in code. So, our code is running. Alright. Now see, this app is also a component. I have told you that you are using this app in main.jsx. If you are not able to understand, then it is not a problem. You have not seen the previous lecture. Go and watch it. Now we move ahead. So, what will I do to explain the component? I will make a component. Definitely. I will make a component to explain the component. So, suppose I make a random card type or square type. So, component is also a type of function, but to call a function as a component is very wrong. I am making a function here. And here I give the name square. The name of the component should always be starting with a capital letter. I will tell you all of that now. I will clear everything now. I am just giving an example. And here return. What will we do here? UI. What is the component? Usable piece of UI. So, I define a UI here. What do I define? I make a div. And here I give it a class. Class name basically. Square. Ok. And after coming to the CSS, in app.css. In app.css, here in the bottom. I select it with dot square. This basic thing is coming that why I am able to write CSS in app.css. In app.jsx, I have written this. And here I have given the class name. And why can I write CSS? I had told you the basics. See here, we are importing app.css. So whatever we will write in app.css, it will be applied here. So I have given it a name, square. And here in app.css, I will give it some style. Like I will give width 300 pixels. Height I will give 300 pixels. And bg color I will give red. So let's see how it looks here. Come on. Now it is not visible here because we have not used it. So how will we use this component here? So in this way you will know the square here and here you can write self-closing in this way or simply in this way. Why is it not giving a suggestion? Okay. You can write in this way too. It will work for you in this way too. You have one square, make the size a little smaller. This is enough and come here and explain it well, I will make it 100, 100, it will be understood well. So this is one of our UI. Now we have made this UI small, maybe this UI is very big. Now if you want to make it again and again, then you have to write the code again and again. But this is not the case in React. You have made a component. You can use this component again and again. Do it this way or better do it this way. If you have used it once, then this component is being used once. If you want to use this component multiple times, then this component is being used multiple times. If you want to give some gap from the margin bottom, then you will give it in one and it will be applied in all. Do you see the benefit? You gave it in one and it was applied in all. So this is the benefit of components. If you see a bug in the components, then you don't need to change everywhere because you haven't repeated it. If you change one place in the component, it will be reflected everywhere. So there are many benefits. I have given you everything in the notes. I will tell you everything. Don't worry. So you have understood the component to a great extent. Now, here I will tell you two types of components. But first of all, I want to take you a little bit behind the scenes. So let's see what types of components we can have and how we can design them. But before that, let me clear you some things so that you can understand the difference between function and component. You have to think that can we do this in function or not? Or is this why components are better? So for now, I have told you that your starting letter should be in upper case. If you make it small, then there will be a problem definitely. You will get an error here. Wait a minute. If you make it small, have I deleted something more? remove it and make it small s so you can see here you are getting nothing control shift i if i do it here so the tag square is unrecognized in this browser if you mean to render a react component start its name with an uppercase letter it is saying that if your meaning is from react component then please start with uppercase letter if your meaning is from normal html then write like this there is no problem And here I have told you that you can write it in this way too. So this is a normal tag. This looks like a normal tag. This is what I want to say here that if your meaning is from react component then please your starting letter should be capital letter. If I make it capital here. So here you can see that all the error will be gone and you will get a box. Let's reload and see that the error is gone and you are getting a square box. Very good. Now let's see in the case of the function. So the function is our normal function and have you ever seen in the function that you can write, you can start from the starting letter in the function. But generally the function that we make starts with the small letter. We are starting with small letter and then capital letter and so on. So, here we define the function in small. So, we are defining the function and we can't use it as a component. But can we use it as a function? Yes, we can use it as a function. What are you saying? Why are you so confused? Let me tell you what I am saying. Here we are writing jsx. Agree with this, we are writing JSX here. Means, we can write Javascript here also. Definitely, we will put curly braces like this. And we can write Javascript also. So, what we have to write in Javascript? I have told you in two lectures that what you have to do in curly braces and what you don't have to do. So, we can do function call. Definitely. So, we will do this function call here. Now, will it work? Wow! It is working now, there is no error. So we can use it as a normal function also. Why are we doing it as a component? We can treat it as a normal function also. One more thing, you have never seen that we are writing JSX in a function. In a normal function, we are doing some mathematical operations. Whatever you are doing in a normal function, you have to do the same as you used to do in JavaScript. You have never seen that we are writing JSX in a normal function. That's what I want to tell you. If you are making a component, then keep a capital letter here and use it as a component. If you are making a function, then keep it in a small letter and there is no need to write JSX here. However, you can do this too. This is not a problem. You can do this too. See, it is working. So the question arises that why should we use the components? If we can do it like a normal function, then why did we make the components? Why did we bring the components here? Normally, we could have made a function and used it in this way. This is working. This is not a problem. So you will understand the problem later. When I will give you the idea of props etc. Ok, I can give you a little idea here too, if you want. I have made two divs here. Ok. Let's wrap it in a fragment like this. This is our two divs. There are two squares basically. Ok. Remove the square too. Should I remove it? No, let the square remain inside the square. Keep it simple. Like this. This is the same as before. Inside it. Inside it. Here we have one h1 and this is another h1 and here we take some parameters. According to the function, it is a parameter. According to the component we call it props and according to the function we are taking parameters here so we take some parameters here this is our para1 and this is our para2 parameter2 so in parameter1 what will be coming we will show here and in parameter2 what will be coming We will show it here. No problem. We are using it like a normal function. Forget about the component. Now we are not going that much. We have seen the component overall. Now I am telling you the normal function that what problem can come to you, due to which the component was brought. So here I gave parameter 1 and here I gave parameter 2. So whatever is coming in parameter 1, it is obvious that we are writing JSX here. So here we can use the parameter 2 variable. So let's send here and see what is happening. So here I send hello and then I send here. Let's see what is happening here. Now I have to increase the size of this. Let's see what is happening. Now if I change the parameter. If I change the alert, I have to keep in mind what I have to write on the first place, second place and third place holder. According to this, your component will be designed. So, you are understanding this problem and you will understand that there is no memory of function and there is no memory of component. There are many things and you will understand. So, for now I will comment it out. You have to keep this in mind that place holder will be kept in mind. Whatever we will give in first will come in first, whatever we will give in second will come in second, whatever we will give in third will come in third. According to that we will have to do it here and we will have to call in this way. Alright, if we want to do multiple, then we can replicate multiple here. There is no problem. So I will put it above. This was our function approach. No problem. This is our component approach. And if we write it in a more specific way, then we can write it in this way. SQUARE and here self-closing. And let's call it capital SQUARE. Or let's comment it for a while. Let's replicate it first. and this function which I have told you, let's comment it and here let's make it capital SQUARE And that's it. Now this is our component. We have written it in capital. We are using it in capital. This is our component. Now this is not a normal function. Now this is our component. So now we are not taking it in this way. We are not taking the parameter in this way. So how are we taking it? How are we taking it? Remember, I told you in the basics. Here we are taking it in this way. In key value pair. So first of all, I want to give title as equal to hello. Okay. And suppose I give here. Leave title. Here in this way. Give name. Minus. And not comma. Give age. Age is equal to. 21 is the number so let's give it like this. Ok. Name-age is equal to 21. And how will we receive here? Here you know that you will be getting only props in object format. Whatever we will send here, whether you are sending name-age 21, whatever you are sending, you will get an object here in the key value pair. You can call it props or object. You can also see it by doing CLG. Props. You must have read all this before, so you must be getting an idea. See this. And it is coming twice because remove the strict mode in main.jsx. All right. Now you can see the name and age. Now you are getting the object as a props. Now you can use it like this. Now there is no confusion here that I have to pass it forward or backward. As it was happening in placeholder that I have to pass forward, backward, up, down, then only it will be arranged like this. There is no confusion here. Should I write name here or should I pass name backward? There is no problem here. We are working on key value pair here. See the name is coming up and the age is coming down. If I do it back and forth, it will be coming in the same way. See, the name is still coming up and the age is still coming down. Why? Because whatever we have sent here, we have sent as a props. Here you are getting as a props which is an object. We are writing it by destructuring it here. So what does it depend on? On this key. Ok, on the key. Here we are using the key. So write in front, write in the back, write anywhere, there is no problem. So this is one thing that happened to you and in this way There are many things like this. You have two types of components. First you have functional component and second you have class component. Now we are going to read functional component here. Why? Because the class component is completely removed. If your code base is very old, then you will see the class component used here. Otherwise, you will see that functional components are used. What we are going to study? We are definitely going to react fully on functional components. But it is not that I will not tell you about class components. I will tell you about class components, but I will not tell you in a separate lecture. I will make a small project. In the project, I will make a project using functional components. Then we will see how we convert that project into class components. You will get clarity that how it was used before and how it is used now. Rest, there is no need to go to the class. No one is going to ask you anything. It will be on the proper functional component. And if something is asked, then the project I will tell you will be clear to you. Okay. And if you have got a project like this, that you have to shift from the class component to the functional component, then you can read it there. There is no problem there. It also has documentation. You can do functional component. It is not very different from the class component. If you have read the class in JavaScript well, then you can do it easily. So, we will discuss about functional component. I will tell you about class component later. But, we will convert functional component to class component. And we will discuss about functional component. So, this is our functional component. This was our functional component. Once I show you how to make you from the class. We make something from the class in this way. We use the word of the class. We use the word of the class to make a class in java script. And this is to make a component called square. So here square extends. Now who will extend? So component. And here we have to import the component. Import. Don't understand too much here. Okay. I will explain this properly in the project. class square extends from component. I don't know if you have seen class and object in javascript. I have told you in detail. Please watch it once. So here we will render and just return as we were returning. There is not much, syntax is a little different here. Rest, we use this keyword here because classes and objects have come. So this keyword will definitely come. So if you come here and see, let's reload. Wait a minute. Our square is made, we are returning it here and here we are returning the component. Wait a minute, someone is calling. Ok, we made a component using the class. And here we are getting some error. Ok, wait a minute here. We made a component using the class, but here we did not use this. You have to do this.props.name here. And now your work must be happening here. So this is how we make class based components. And this is how we make functional based components. Now, how exactly it happens, you are not able to understand it. You don't even have to understand how to work in a class-based component. One project is very easy. Believe me, it is very easy. I will tell you one project in a functional way. Till now, we have been doing it in a functional way. We will do it in a functional way in the future as well. And in the middle, I will tell you one project in a functional way. After that, you will be converting it into a class. Everything will be clear to you. And those who don't have any idea about class, I will explain a little bit. So, you don't have to worry for that. So, you have seen two types of components, functional components and class components. In modern way, functional component is the only one. Older, you can say, class component. Some time ago, class component was still in discussion. Now, it is completely over. If you see the new React documentation, then it is based on functional component. There is no discussion of class. Okay. So, you have understood this too. Now, actually, we will dive into components. And what we will use? Functional components. Okay, so for now take a little break, then after that, you will understand functional command that returns yes. No need for this keyword. There is no use of this keyword. It is very clean. We are using hooks in functional component. I will tell you that too. In class component, we do something like this. It is an older style. We use our render method. And still seen in legacy code base. It is a very old code base. You will get to see it then. Otherwise, no. I have already told you about props. Let's see how to work on props. State, memory of component. This is very important. Let's see everything. There are more things ahead. Take a little break here. We have finished here. We will discuss props. Before that, a little break. Now let's understand how props are very useful to make any component dynamic. Now what is the sense of dynamic, I have just told you that if there is any component, then you can use all the components. You can use the same component multiple times wherever you want. But the data will be the same in all, now if you want the data in different, dynamic, that we can use all the components with our own data. So here the feature that sends you props, react provides. Now how can we do it? So let's see here. First of all, I make a folder in SRC. I will make a simple card component in components. This is our card. We will make a small class named card. We will not do much in card. We will give a title in the card. H1. Some title will be coming here. Paragraph will be coming here. Some description will be coming here. This is our small card. Let's style the card. And how will we style the card? Now definitely we are going to use app.jsx. In app.jsx, app.css is also applied. If you don't know where to use css and how to import it, then you will get the idea. For now, you have to come to app.css. App.css is imported here in app.jsx. In app.jsx, we are also going to use the card, so that css will also be applied in the card. Trust me and go to app.css and type dot card. Why dot card? Because we have given the class name card in the card. Ok. So here dot card and we will style it. We will give BG color. Light sea green. And we will give a little bit of padding of 30 pixels. And we will give the border radius of 10 pixels. So it will look a little bit like a card. Not too much but it will look like a little bit like a card. Nothing is coming here because we haven't used it yet. Let's come here in the card. And let's use the title description in app.jsx. I have commented everything. I have commented everything that we have just read. So come here at the bottom and if you want to keep it a little clean, then you just focus on this app. And come here and use the card. And as soon as you enter, it will be imported automatically. Now you can see the card is imported and now you can see the title and description of the card. Now I am able to use the card in this way. I am able to use multiple cards here. Let's make it a little more stylish. Let's create a div here. And let's give it a class name. Grid. And here by selecting grid. Dot grid. Okay. We will display it. Grid. Grid template column will do three. And let's see here. This is something applied or not. in app.jsx we have given the class name as grid and in app.css grid is very good display grid, grid template, columns, oh I am sorry 1fr, 1fr, 1fr here I enter in tailwind again and again, it is very easy in tailwind You can also use repeat property here. I will give a gap of 20px. Now you can see something like this. We have done the styling, now you have to focus on the styling. Don't do it if you don't want to. The important thing is that we are using the card component by replicating it. But all are the same card. We are not able to make it dynamic. All have same data. We don't have to use it like this. We may need the data of this card, we may need something else here. So what we will do? So definitely you will get props here. You will receive props here and send props here. So how do we do it while sending? In the key value pair. Like I have to send the title, so I can give the key here. It is your choice. Give the name key, give the name. You just have to do the access in the same way. The way you will give the name of the key here, you have to access it with the same name. So like I give the name of the key here and in the title I give the name of the first card and in the title I give the name of the first description. In the same way, I will replicate it like this for the time being. And here I will change the title. First, second, third, fourth and fifth. So this is our first, second, third, fourth, fifth. And let the description be the same. If it changes, you will know that it has changed. And change the description according to you. Now how will we use it? The props that we have sent, it still looks like this. Because we have sent the props, but we are not using it by receiving it. So I will write here props, you can give any name. Whatever key value we have sent, just remember that it will come as an object. Whatever name you give here, it will be an object. name it props, name it object, whatever name you give, it will be an object. So I give the name here props. And what will we get in props? If you want, then you can see what you are getting here. You come here and see. Here you are getting all the objects, here is the title, there is a description that you sent. Very good. So here we have to write java script curly braces open close. Here we will do props dot title. Okay. And here props. description alright so here you can change title and description so we can make components dynamic with the help of props not only component but also dynamic components Alright. So, what are the benefits of props? First of all, you can call props properties. They are the same properties in object. Like we used to call properties, these are also properties. Props are not here. Pass from parent to child. You are passing from parent to child. This is very important. This is asked in interviews. That we pass from parent to child. But if you have to pass from child to parent, without Redux toolkit or context API, you don't have to do anything else. You have to use core react and pass from child to parent. Using core java script logic. So, how will you do it? This is asked from you. So, first of all, understand this. You must have understood that here is your app.jsx. This is parent. Inside that, you have card. This is your child. So, whenever you are passing props, if you are passing from parent to child, then you saw that we were using card in parent. So, we were sending props in card from here. So, from parent to child, We are passing props to the child. Now in the interview, you are asked that if we have to pass a prop to the parent from the child, then how will we do it? And we have to use CoreJS, we have to use Core React, Context API, Redux Toolkit, we don't have to use anything. Now you haven't even heard the names of all that. Anyway, forget that. How will we do it using JavaScript logic? So you think a little and tell me. normal javascript logic is needed. If you think about it, it is a very good thing. You have done javascript very well. And if you can't think about it, then don't worry. I told you about props in a separate lecture in the starting. That it is going to come. In that, we will discuss all the things, interview questions, everything. So never think that this is getting skipped in this, so it will not come further. It will come. Props is our property, we can call it pass from parent to child. If you say generally, then pass from parent to child. Although there is a way to pass from child to parent, we can make logic. Read only means that you can't change it. Like the title is coming in props. You want to change the title to alpha, then you can't do this. If you come here in the browser, then you will get an error here. that you cannot assign to read only property. You cannot change read only property here. So, what is props? It is read only. So, you don't have to change it by mistake. So, I will remove it from here. Very good. Now, your error will also be gone. So, read only property. Props make components dynamic and reusable. This is the benefit of props that you can make components dynamic. You made one UI component and in that can change the data in it and use it in multiple places. So props are very good. You must have understood. Now let's move ahead and understand the state which is the memory of the component. It is very useful. Now this is the thing that you will not get in the function. Although you were not getting props in the function. I told you this in the starting itself. You could have taken parameters there. So one is props, which is a special characteristic of the component. You can say that you do not get it in the function, you get it in the component. After that, there is another specialty of the state. That the component has its own memory. So to understand the memory of the component, you have to keep one term in mind. That is state. Now why do we have to keep this in mind? Because state means your data. Now what is the meaning of component memory? Component will have its own data. Every component will have its own data. Now we were looking at 1st, 2nd, 3rd, 4th. So all components had their own data. They were sending props. Right? But if in component itself, something like that has to work, something related to data, then how will component persist its memory? How can we make it do all those things? It does state. Data that changes inside state. If you want to understand state properly, then state means data. Component's data. One component, second component, third component, fourth component. The data of first component will be different. The data of second component will be different. The data of third component will be different. Similarly, the data of fourth component will be different. So this data is the state. The state of first component. The state of second component. The state of third component. Okay? State means data, data of component. You can send data like props but there are more ways, I will tell you that. Managed with use state in functional components. Functional components, I told you there are two types of components, functional components, class-based components. So in functional components, we use use state to manage data, to manage state. There are many more things ahead. State management is a very different topic. But for now, you will use useState everywhere to manage the data. Whenever I say state, you have to understand the data. To manage the data, we are going to use useState here. And props are your external input. If you want to send external data from outside, then you have props for that. But if you want to make some internal data, then your state is for that. That's all you have to keep in mind. This is any component. Components have data. It is possible that the data has been sent from outside. If the data has been sent from outside, then it will be your props. And if you are making your data inside, then you can make it using useState. So this is your data. State, data, component's memory. It is very easy. There is nothing complex. People say state, state, state. Data is simple data. Now send data from outside or make it inside. You are sending from outside. There are props. You are making it inside. It is state. It is your data. Alright. Shall we try it? Let's try it. It will be fun. Let's do it quickly. We are sending the data from outside. Now I want every card to have its own data. Listen carefully, every card has its own data. As soon as I create a data from a use state in the card, every card will have its own data. I am repeating the same thing again and again. But this is the thing that puts you in a lot of confusion in the future. You are not able to understand why this happened. This happens because every card has its own data of every component. So if I make data here, then how will I make it? I have already told you this. So here we will do state comma set state or whatever name you want to give. Let's make a counter and see. Count set count. Count and here set count. What does set count do? definitely, value changes, the data we made, this count variable will be your data, set count, we can change that data, and it will reflect everywhere, how to do, use state, and assume, initial data, we give 0, ok, initially, count value is 0, and here, we also show, h1, and here, we will use curly braces, because in java script name, count, alright, so here, see, all have 0, so you will feel, that all have same data, Is it the same data? I just told you that all the components will have their own data. How will we know? Let's see. Let's make a button here. and write increment in the button and all this is coming to you, we will put onclick and here we will call an increment function and we will make this function here, you see there is a big difference between function and component, this is your function increment that we will make here, function increment, so wait a minute, In increment we will set count as plus plus. In the old count we will set plus plus. If the old count is zero then in zero it will be plus plus which means it will be one. Then if we will increment once more then it will be plus plus which means it will be two. Then it will be plus plus which means it will be three. We have already made counter app. Now we have the increment button and in the starting it is showing 0,0,0,0,0 Now we have to check if everyone has their own data or not. So how will we check? If I click on this component, then only this one's data should be changed. If everyone has their own data, then only this one's data should be changed. Do you agree with this? Let's see. Nothing happened. Assignment to constant variable. Wait a minute. What did we do? Did we do something wrong? Everything is fine. We are doing set count. Count plus plus. And here our count is showing. Function increment. On click. What problem came? Assignment to constant variable at increment. hmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm So, everything has its own data. Otherwise, everything changes in one. See, there is only one component. Have I made any other component? There is only one component. We are using the same component again and again here. So, whenever you are using, every component creates its own data, its own memory. That's all I want to tell you. And this is very important. You have to keep this in mind. Whenever you are doing map, you get confused. Why is this happening? Because every component has its own memory. So I will tell you again that everyone has their own memory, so you can work like this. When to do it outside, when to make a memory inside the component, you will get an idea of ​ ​ all that. Did you understand? Did you understand? Okay, you must have understood, here it is being incremented, here it is being incremented, here it is being incremented, so everyone has their own memory. And further we will go to understand the state better. I was telling you that you will get an idea. I told you in the starting. So you must have got an idea. To understand in a simple way, state means data. In components, data can be in two ways. Either you can send data from outside as a props. Or it can be internal data. Which we call state. Use state. Very good. Let's move forward. Components composition. Now the simple meaning of components composition is that by combining components, you can make big components. And you can use that component in another component. Means nested components. Inside one component, inside another component, inside third component. Now the app.jsx was yours. Inside app.jsx. Inside jsx. We are using card component here. It is possible that we make a component inside card component also. You can make it. Make it and see. This is your assignment. You will make it yourself. You will make it and see. Inside one component, inside another component, inside third component. How can we make it. Rest of the projects are going to come next. So you will get an idea about the project. Before bringing the project, I will tell you a little bit about CSS and Tailwind CSS. So that we can make the project well. Okay, so you got to know that component composition means nested components or you can make complex UIs by combining them. So what happens with this is that the UI becomes a little modular. If you change one place, it will change everywhere. If you are keeping it in a modular way, if you are keeping it in a component way. So you can also make complex UIs by combining small components. Component life cycle, we have to read this in detail. That's why I told you in the road map that this is the part of phase 3, but I will tell you a little bit. We say that the component is being mounted on the load. If we are changing something in the data and according to that we need some change, then we say that we have to do the process of updating. Mounting, updating and unmount means component is unmounting like one page is loaded now you are closing that page so that is your component unmount now on unmounting you have to do something like clean up so you can do that clean up now how can you do that use effect hook you have there are many more things so we will see mounting updating unmounting This concept is from our previous class. We do this with the help of hooks in functional components. We will discuss component lifecycle later. Now you have to remember three phases. Mounting, Updating and Unmounting. Mounting means the load of the component. For example, if we click on a pop-up and that pop-up opens, then that component is mounted. If you click on about page then about page will be mounted. Now you are moving away from about page. About page is being unmounted. You are making some changes in about page. That about page is being updated. So we have to see how we deal with data on mounting or we clean up data on mounting. If we talk about class based then component did mount, component did update, component will unmount. We work like this. I will show you in both, it is the same mounting, updating and unmounting, component will mount, component will update and component will unmount. In function we use useEffect hook to manage life cycle. Is it clear? No, it is not clear. It will be done in phase 3, it is not a problem. What are the best practices? First of all, you have to keep the component small and focused. Small and focused means whatever component you are making. This does not mean that if there is a big UI, then you have to keep it in one component. How do I explain? Wait a minute. This is a small component. Suppose you have to make a bigger component. You have to make a bigger component than that. Like this. We have to make a small component, a big component and a bigger component. Now what can be the method here? The method can be that you will say that we will make this small component in one file. Suppose we give the name of the file as alpha.jsx. So we will make this component in the alpha file. Then we will make the second component in the beta file. Then we will make the third component in the gamma file. So these three components are made. Okay. But there could be a better approach than this. This is a small component. The code will be very small and focused. So we make it in one file. Then this is a little big component. And suppose if the code is small, then you can make it in one file. Beta.jsx. It is made in one file. Suppose this whole code comes in 100 lines. But this is a very big component. Suppose you have 300 lines of code. If you are making 300 lines in one file, then it will be a disaster. You can break it a little. You can make it a little more modular. So that it is easy for you to understand what is happening here. In one file, you write multiple lines of code. It is better to break it a little. Like this was our gamma. Gamma.jsx. Suppose we break this gamma in component 1. component 1 or upper lower break something like this is gamma so upper and lower I have broken it in two components cut it from the middle ok this is one component this is one component the code has also become small and a little modular you are also able to understand well so these are all best practices, although you will understand better in the project, here it will not take much time, wait a minute, let me take the stroke eraser ok Use Pascal case, I told you that starting letter should be capital and better is to write in Pascal case like this starting letter capital and then small small. If you think that some different word is coming here, this word was different, this word is different, then here capital one more letter and then small letter. Reuse logic with custom hooks instead of duplicating. Now we will also It is very important to reuse. It is not that you are reusing the UI, but the logic written in the UI. You have to write the logic in such a way that you can reuse it again and again. If that logic is in a lot of places. What does logic mean? First you are able to understand this. Logic means your login functionality, logout functionality. It is possible that you have to give the logout functionality in two places. One profile here in the section and one somewhere in the middle here. So, you will write logic in one place and use it in both the places. So, in this way, custom hooks can also be created here. You will not understand custom hooks now. We will read context API and so on. So, you will understand there. So, for now, close your eyes here. Okay. We will see further. Separate. Now, I tell you together because at least you will get an idea that we are going to see these things further. I don't tell you to confuse. You just get an idea that it happens in this way. And what is the best practice? Keep UI and business logic separate. In this project, you will understand better how to keep UI and business logic separate and how to use UI multiple times. If one logic is being used again and again, then how to use it in multiple components. All those things. Okay? Components vs. Functions. Did you notice? I told you in the beginning that you should note what are the things that we can do in components and not in functions. And that's why components are better here. Functions have their own advantages and components have their own advantages. So first of all, definition. A block of code that performs a specific task and returns a value. It is possible to return a value or not, it is not a big deal. It will perform a task. React component is a special function or class that returns a JSX or you can say UI which is describing a UI and returning JSX. What can be the return value here? It can be primitive value, object, array, anything. But what component will return? UI, JSX or null. If it is written for logic, it will not return anything. Otherwise, UI will return, JSX will return. Naming convention can be in both lowercase and uppercase, but mostly we prefer lowercase to make functions. But in react component, your starting letter should be capital. In Pascal case, your starting letter should be capital. In Pascal case, it is better. Input is one parameter argument. We send parameters here. You know that parameter depends on what is in first place, second place, third place, placeholder wise. In this, props depends on key. Keep the key back and forth, there is no problem. Receive it in object format. So here we are sending props and here we are sending parameters. Parameter is working in argument format and here in props format. If we talk about usage then call directly like this. We are using it like this and here you have understood it like this. If we talk about state handling, then the function doesn't have built-in memory. The function doesn't have its own built-in memory. The component does have it. I just told you. The component does have it. I just showed you by doing it. So, here you can use state, user, user and many other things. You can use it in the future. So, state management is a great thing. You have seen the roadmap, right? See the roadmap, you will know everything. Reusability. We can write reusable logic here. I just told you that we have to keep logic and UI separate. So we can make logic a function here and UI a component. Okay. Okay? So reusable logic but not tied to UI. Okay. Tied to UI. Here we don't have to do anything with UI. Here we are just writing logic. Here logic plus UI both can be written. Here logic plus UI both can be written. UI is also written along with logic. Now like counter is made. Counter. Small application. Card one. Counter one. So there we were also writing logic inside the component. Okay. So if we talk about life cycle then function don't have life cycle. But component has life cycle. Mount, update, unmount. mount, update, unmount, mount means when it is loading, update means you are updating some data, unmount means you have understood, if it is removed after unmounting, then if you have to do some cleanup, then there is a life cycle and the life cycle has to be understood in detail. Alright. Why component? Now anyone will tell you this. Why component? Tell me. Reusability is the first thing. Write once, use it again and again. Right? Write once, use it again and again. Don't repeat yourself. It follows the dry principle well. Maintainability. Code is easier to manage. Change one place, everything will change. Suppose you are getting some bug in the component. Now what would have happened if you were writing that code everywhere? You would have to change everywhere. Now if you change in one component, everything will change. Readability. It becomes very proper. You can see that this component is working and go to that component and check the code. Scalability increases and you can scale the application. You can break the component and use it to make a bigger application. Summary, components are building blocks of react, functional components are standard, props, input, state memory, composition makes app scalable, Life Cycle Managed with Hooks Functional Components Life Cycle Managed with Hooks Advanced Patterns Advanced Patterns, Reusable and Maintainable Apps. Those are the things. I will discuss advanced patterns one more time. Higher order function, uncontrolled component, uncontrolled component. There are many more things. That is why I have written advanced patterns here. So, in advanced patterns, it is not like reusable and maintainable apps. Reusable and maintainable apps actually means that there are many more things internally. Advanced patterns and reusable and maintainable. This is the line I have written here. I have written this so that I remember that I have to tell more things in the future. I have written that for my reference. There are many things like control, learn control, component. So I will tell you that in the future. I will also tell you advanced patterns related to this so that you can understand and manage the components better. So I believe it will be so far. It will not happen further. I hope you understood. I'm still a bit late for the videos to come but I can't do anything as I have to roam around a bit. Anyway, I'll try to bring it as soon as possible. It's not a problem if the shots come now. So, I'll meet you in the next video. Till then, bye-bye.