- Podcasts
- ReactJS Developers Podcast
- 5 Ways to Render Lists in React JS | Master Dynamic List Rendering
5 Ways to Render Lists in React JS | Master Dynamic List Rendering
ReactJS Developers Podcast
- December 3, 2026
- 44 min
- Episode 27
About this episodeRendering lists is a fundamental skill every React developer needs to master. Whether you're displaying products, users, comments…
- Understanding list rendering in React JS.
- Rendering lists using JavaScript's map() method.
- Using filter() to display selected items.
- Combining map() and filter() for dynamic list rendering.
- Rendering lists from arrays of objects.
- Creating reusable components for list items.
- Understanding the importance of unique React keys.
- Using conditional rendering with dynamic lists.
- Handling empty lists and missing data.
- Common list-rendering mistakes and best practices.
- Beginners learning React JS.
- JavaScript developers transitioning to React.
- Frontend developers working with dynamic data.
- Students building practical React projects.
- Developers interested in writing cleaner and more reusable React components.
Transcript
From the publisherThis transcript comes from the podcast’s own feed, shown as the publisher wrote it.
5 Ways to Render Lists in React JS | Master Dynamic List Rendering
Today I am going to tell you how you can render a list and what strategies you have to keep in mind while rendering a list. and what are the beginner mistakes. I will tell you all these things. And you must be feeling this is a repetitive topic. In the previous projects and in many cases you have already done this. So definitely you will feel a little repetitive. But you will get to learn a lot of new things here. And you will be practicing in a way. First of all, what is list rendering? You did it but you didn't know the name. List rendering means that you have a list, you can have an array. Generally, you get an array and you have to list the array. Although you can map the keys and values of the object separately, but you have to make an array. Because you can easily run a loop on the array. At the end, you will get an array. It can be any array. You will have some items present here. Now, how will you render these items and show them on UI? That is called list rendering. You will have different items in the array. It can be object, string or nested array. How will you list all of them on your UI? How will you show them on your UI? You will have to do looping. Here you can't show array of 0, index, 1, 2. You don't have to do this. You will have this array from the database. We will do it locally. In future you will get full array and data from database. So how you will show definitely we are going to know all that. So here we will use mapping definitely. We can't do loop as I told you earlier. Whatever java script we are writing here. Here your expressions are allowed. You can't use statements here. So definitely you have to write expressions, you can use functions, you can use variables here. So you can't use loops. You can't use looping statement or if else statement. So the question is how to do loops? So your answer will be ready that you will use map. Now my question is why will you do map? Why can't you do for each? You can also use forage, we have read it in javascript. So why do we have to use map and not forage? You tell me, till then I will show you a basic loop. Keep it in mind, why can't we do it? You have to comment and tell me. So let's come here in the code and zoom a little bit, it will be enough, everyone will see it in the mobile device and I will close it here and our project is running, I will tell you that we are still using Vite, that is, we are using Vite from the beginning, so we are using Vite here and with that tailwind CSS, if there is a need, then we will use tailwind CSS, I have set it up, you can do it according to you. So, our project is running here. You can see HelloManus here. I have zoomed it. Now you can see it. But we will keep it as it is. So, first of all, let's make a small array and test how it is working. So, let, not let, const. We don't have to change it in array. And one more thing. I will tell you later. Leave it. const array is equal to. Here you have some items like minus and Muskaan and Mehak. You can take any string in array. And we have to map this array. How we will do it? It is very simple. We have to map array. We have to use java script. We will close curly braces. Now we have to map it. So array.map. We have read map definitely. We don't need to use statement, we need to use map function. Array.map and map is a higher order function. That means, you will call the function but you will also be taking a function. So, give a function in it. So, here is our function. I told you to listen to me carefully. We have done this. Here is our array. We have to do map. We have done dot map. It is a higher order function. We have called. Now, this is a higher order function. So, you will be taking a function in it. So we will give it a function. Here we have made a function in it. What have we done in it? Just made a function. Now you can make any function. If you have a fat arrow function, if you have a normal function, then here you can see the fat arrow function written in this way. So it is your choice. Let's do the fat arrow function. So this is our FedRow function. By default you get 2-3 parameters in which the most useful parameter is 2. If you want to know the depth of the map, filter, radius, and forage in detail then you can see the array lecture in javascript. So here you get 2-3 things in the map in which 2 is the most useful. The first is the parameter item. You can name it as you like. You will get items. I will show you the item by doing CLG. You must be getting the item by doing it one by one. Remove the strict mode from here. Otherwise, it will be visible twice. We don't need it now. Close it and come here. Let's reload. The first time there was a minus, the second time there was a hack and the third time there was a smile. Now we have to render it and show it. To show it, you have to create any tag like h1 tag, div tag, whatever you want to make. And here you have to show this item, so I have put curly braces. And here we will insert this item variable. So in the first time, the minus will come, then the minus will come, then the smile will come, then the smile will come, then whatever is coming will be seen. Alright, so will we be able to see? My question is, will we be able to see? Then we won't be able to see. Why won't we be able to see? I have told you this in basic JavaScript as well as while making projects. Quickly tell us why we are not able to see the output. We have done everything correctly but still why are we not able to see the output? Have you told us? Say it in your mind or say it in front of you. It will be good. You will also be getting things slowly. Otherwise, You will be stuck in the bug that why it is not rendering. What mistake we have made. There is no mistake here. You have not returned. I told you that whenever you use the syntax of curly braces, you have to return. Otherwise, it will not be visible. So you have done return. And here, is it not visible yet? It should be visible now. Our item is coming. Each child in a list should have a unique key prop. So let's give the key now. And I will explain you the key now. So let's give the item. But it's not looking good. It's looking good. So why is it looking like this? Have we done some useless style? Look, it's coming down. Like this. Wait a minute. We have spread some garbage. Okay. What have we done? Remove this. Now it will be perfect. Very good. Okay. So our work is doing. I did some useless style in index. Okay. So that's why it was coming here. So, here you must be seeing something like this. Hello minus is coming from here, from this place. And if you don't give key, then you will get warning. And I will tell you a little bit about key in the future. And in the previous lectures, I gave you a key depth idea. I believe in the state lecture. Yes. I told you in-depth diagram that why it is very important to use key. Although I will tell you now. But if you want to see that much depth, then I tell you again and again, follow in sequence. So, here this is our Hello minus is coming from H1. If we don't return, we won't see it. Otherwise, you have another syntax. If you don't want to return, use parentheses instead of curly braces. If you use this parenthesis instead of curly braces, then you will not need to return, it will be automatically returned to you. And you have to use the key. You have to give the key so that you can identify uniquely. Here different children are being rendered. To identify children uniquely, you have to give a key. And the key should always be different for all of them. So, what does the key give here? Now see, all the items are different here. So, I can also pass the item in the key. I have passed the item in the key because all the items are different here. So, there will be no error here. But if I do the same with two items, like this first one is also minus and the second one is also minus. So, you can see here that I have encountered two children with the same key. Two children are coming with the same key. This error is telling. So in this way, to identify uniquely, that if you are right by mistake, but if you use two items of the same key, then you will get an error there. Which is an obvious thing. Why are you using the same key? And if there is a similar use case, then you can handle it according to you. Let me give a minus for the third time. Let's reload. Encounter two children. Same error is coming. Give it twice or thrice. Basically, it is telling that three children are being rendered. multiple times. See if there is a copy. So, here I will make it mustan. I will hack it. So, what is the use of key? To identify uniquely. And how does it do? What does it do? What is the internal algorithm? I had told you all that. In the lecture on state, I believe I had told you. So, if you are following from the starting, then I had told you by making a tree there. That here your memory is made separately like this. It is linked. And there key is identifying you uniquely. If you have given the key separately, that means your state will be different. I had told you a lot of things like this. So maybe you remember it or not, you can see it once. The rest of the concept is enough, there is more than enough for development. So this is our rendering. So this was the basic of our list rendering, that you can do list rendering in this way. And you must also know this much. So list rendering means displaying multiple items like data from an array in JSX. We use JavaScript dot map method to loop through data and return JSX element. We do loop through data using map and return JSX element. Now my question is why to use map? We use function and all right expression and map is a function so we can use it. But why not use for each? There are two strong reasons. First one is immutability. Immutability means not to change. don't change in some original things like if you have made an array 1,2,3 then don't change in original array that is called immutability don't change in original array you can make a copy of array and return new array you can do this kind of work so you must know the map I have told you very well in java script map, filter, radius all things so your map A new array is returning. Whatever array you are mapping on, array.map, it does not change the original array. It is manipulating and returning a new array. No change in the original array. If we talk about foreach, then foreach is not returning any new array. If it will not return, then how will it render on UI? I just told you that if it will not return, then how will it render on UI? So foreach is not returning. Okay? Rest, you can do the task according to you. If you want to manipulate, then definitely we use foreach. Rest, if you want to return, then we use map. So, we definitely don't want to manipulate. We have to focus on immutability. We don't want to change in the original array. So, here we will use map. Why we use dot map? Okay, I have already told you the question. So, here you can read it once. React works with immutable UI updates. It focuses on immutability. And dot map creates a new array without modifying the original. Dot map is creating a new array without modifying the original array. It does not modify the original array. And this is very important for us. That it does not modify the original array. That's why we don't use for each, we use map. Very good. And if the concept is not clear, then definitely go side by side and see JavaScript. I am saying this in every lecture. JSX can embed JavaScript expressions inside. Those who have seen JavaScript before, they must be having a lot of revision. So, it will be fun for those who have seen the premium JavaScript course. JSX can embed JavaScript expressions. I have told you that whatever you are using in JSX, you use expressions here. You don't use statements. So, we can directly use array.map in our JSX return. So, you can use array.map easily because it is an expression function. You can't use statements like for, while, do, while. You can't use all these things here. Okay? Are you clear on all these things? Alright, let's move on. Now different types of array to render. I am not teaching you different types of array here. Whether it is a one-dimensional array or a two-dimensional array. What I mean by different types here is that how can you get the data? And how do you have to handle it? What strategy should you have? Did you understand? Listen to me carefully. I am not teaching you types of array. Types of array means how you can get data in array and with what strategy you have to handle. I will teach you this. Don't go into types of array. What I am telling you is not types of array. I am clearing it. Types of array is not 1D, 2D. What kind of data you can get? Generally, the format in which the data is coming from the database, I am going to show you that you can get data in this format. And you have to handle this format with this strategy. Okay? Let's move ahead. So, first of all, the normal array, which I just told you. There is nothing much in the normal array. You may have all the strings. Or you may have all the numbers. So, there is no problem in rendering this. If it is a simple string with all the numbers, then you will definitely get an item. Here we have given a name, so you will get an item. And you can definitely use index in the key. I don't know if I told you or not, I told you about the index. You are getting an item and an index. You are getting the same index in the sequence 0, 1, 2, 3, 4, 5, 6. If you see the index here by doing CLG. If you want to see the index and here I will get an error, the error will be given because the syntax of curly braces is used here. So sorry, the syntax of parenthesis is used here, so we can't do console here. So let's convert it from the syntax of curly braces. Take our curly braces. Take this. Okay. And our curly braces are done and here the return is very good. Now we can do console and return also. So index is 0, 1, 2. There are only 3 elements so our index is going to 2. Where is the code? Here it is. So you understood the index. You can also give index in the key. If the items are same then you can handle by giving index. You will get different index. So, it is working properly. There should be no problem. So, this is a normal array. In a normal array, you can have strings, numbers, simple values. After that, the second thing you get is an array of objects. That means, you can have multiple objects in an array. And generally, you are getting data in this format. The data coming from the database is coming in the same format. Most of the time it is coming in the same format. So it is very important to handle it. So how to do it? You have to do the same way. I will show you. This one is understood. Now const array is equal to this array. Now we make each object here. We give ID, name. minus kumar lal and then we give 21 as. So, this is our one object. Similarly, multiple objects can be here. Now, how to map it? So, it is the same simple method. I will comment it out. Follow the same approach. Just there will be some changes. So, here our array is coming. What is array? Array is coming. We will do dot map. Alright. We will give a function here, very good, here we will be getting items and along with index. So leave the index now, we don't need index here. We will be getting one item. Now what is the item here? There is one object. Our item is one object or we can say that there is one user. Data of the first user, data of the second user, data of the third user. You can say that there is one user. You can name the item or the user as you wish. You will get an object. I can give you a proof by doing CLG. As you were getting one item there, you will get one object here. That's it. You are getting one object. Very good. Normally, if you want to render this, you have to pay attention to the curly braces and parenthesis. If you are giving parenthesis, then there is no need to return. If you are giving curly braces, then there is a need to return. So, we will return here and we have to show ID, name and age. We have made a div. Here we will get an ID. So, this is our object. So, we have to access the ID in the object. So, how will we access? User.id. If we have to access any key in the object, we do it in the same way. User.something, object.something. So, user.id. Then, after that, our here, h1. Here, what will we get? User.name. What else did we have? See, name was age. So, here, in paragraph, user.age and it will be rendered here. Let's give it a card-like feel. Let's give it a class name, bg-light-c-green. And let's give it a little space. How to give space? Let's give it a margin, the pipe space will come from the top. will make here, you have to make changes only in the data. This will be your automatic handle. Now if you make changes in the data, this will be your automatic handle. Like I am making a reward here. I will change it to age 19 and you can see it is rendering automatically. So you have to handle it this way. You should get normal array and object. There is no problem in rendering. You have to change the strategy little by little and you can do it easily. So, very good. We have simply mapped. We have returned here. And we know how to use object. We access with dot notation. So, here was one object. We want ID. So, dot ID. We want name. Dot name. Age. Dot age. That's it. Okay. So, now we will comment this. This is the second way. Generally, you will be getting data in this way. Let's see what else is there. So, I will comment this too. I will comment this too. This is our array of objects. And this is our normal array. Now let's see the third. What is our third? The third one is array of arrays. This is about nesting. There is array and there is array inside it. How to handle it? You will understand by breaking it into small chunks. Forget about the array inside. You know how to handle outer array. Let's handle outer array first. For that we have to make an array. const array is equal to array inside array. So here we have html, css, react and java script and then we have mongodb nodejs node.js, express.js, aws, and let it be this much. Learning is something else, I am doing something else. So, we have the array, so let's handle the outer array first. So, the same way, array.map, here is a function, alright. Let's do a little reload format. Now, we will get one item here. Now, let's see what item we have. CLG. So now you can tell what item is coming. We have mapped this array. You must be getting one item. The first item is this. The second item is this whole array. So you must be getting the array. So come here. Let's reload. See this. The first item is also a complete array. The second item is also a complete array. The first item is also an array. The second item is also an array. Now how will we handle? So to handle, you will do something like this here. Something like that. Wait a minute. I had to return it here. Because we have used the syntax of curly braces. Oh man. Come here. Okay. So, in this way, the item is an array. So, if you don't understand, give it an array name. Okay. Otherwise, let the item remain if you understand. So, item of 0 index. You see what is coming here. HTML is coming. MongoDB is coming. Okay. You have only two items, right? You have only two arrays. Look carefully here. Oh man. Reload. You have two arrays. You have the first element from both arrays. If you want to show the second one, you have the second element. If you want to show the third one, you have the fourth element. Third index means the fourth element. So the fourth element has come to you. But we generally don't do it like this. We have to map here too. Is there an array in the array? Very good. What is there in the array? There is an array. So we have handled the upper array. Now we handle the lower array. So what will we do here? We will make a fragment like this. Very good. We have made a fragment. Now what will we do in it again? We will map. What will we do? We will map. So now what will be the array here? The array will be our item. Okay? Item. Let me clear all the things. Simple array was here. We have mapped array. All the items are array. The first item is also array. The second item is also array. The third item is also array. This is the same way to handle array. So, we have returned here. Very good. In this way. So, we have to do item.map here. Definitely. In this way. So, we have done the map. Now, we are getting the error here because you are doing the item.map directly in this way. Parenthesis. Either you remove it from here. Okay. Still, we are getting the error. That's why. I will see syntax wise. Will I have to do it in this way? No, no, no. Here you have to use JSX. Okay. Normally we were doing return like this. We have returned. Now you have to write html here. So we don't have to write html. We have to handle the array. So we will wrap it with simple fragment. Our error will go. We have wrapped it in simple fragment. Now again we have to write javascript in it. Because we have to map this array. So how will we do it? We will put curly braces like this. And this is our array.map. Now another function will come in it. So understand in simple chunk. It will be easy for you. And here you return it and you will get the item here. Let's call it a nested item. And here you are H1 and you show the nested item in this way. Very good. Let's come here and see, you can see it. So the first array was so far. Javascript was there. I believe Javascript was there. So the first array was completely destructured here. And the other one is the same error. So, you can handle it this way. It depends on the use case. How to handle it? It depends on the use case completely. And the key error is coming here. So, the first time we have mapped here. So, to map, we don't need to give the key here. But we need to give the key here. We are returning here. So, we will give the key here. We will give the nested items here. Because all the items are different here. I have to give it in this as well. So, make a div and give the key here as well. Now, I think the error should be gone. It is gone. Now, this is the complete array of items. So, it is better to give index in the key. Give index here as well. If you are feeling confusion, then index is better. Give index in the key here as well. Did you understand? No. Very good. I told you that there is an array outside. We will do array.map. This way. It takes a function inside. So, we have given a function like this. Now, what we have to do here? We have to return. If you don't want to return, then which syntax will you have to use? This parenthesis one. Now, what we are writing in this? We are writing our HTML in this. So, do we have to write HTML or not? So, you can wrap it in a fragment like this. Or you can wrap it in a div, it's not a problem. And you have to give the key definitely. So, you must be getting an item here. You are understanding that each item is an array. So, we call it array item. And you must be getting index here. So, we will give index in the key. So, we have given index in the key. So, the first outer array is handled. In outer array, array item was coming, index was coming. We have given index in the key and we have rendered this div. Now if we write something here, then this will be rendered twice. Why? Because we have two elements. There are only two elements, look carefully. In this array, the first element is done, the second element is done. So it is rendered twice here, so we are seeing something twice. But we don't want to show anything. What we want to show is that we have to destructure the array inside. Basically, we have to loop it too. So here again we will put curly braces. This is array item. This is our array. Dot map. This will also take a function. We have given a function like this. We have put curly braces. So we have to return. So we have returned like this. And here you will have an item. So the item is a normal string. So there is no problem. You can give any name. And along with index. All right. Now whatever you want to do here, you can do it here. Here you have to show the item. Show the item. Along with that, give the key so that you do not get an error. We have given the index in the key so that you can identify uniquely. Let's reload. Proper is coming. Okay. Look carefully. This sequence will be coming. First, it looped. Now, the first item is this. Now, in this item too, it is looping one by one because we have run the nested loop. We have done nested mapping. So, first HTML, CSS, React, JavaScript. The first element was completed. It went to the second element. Then, again, the nested loop was running. Then, MongoDB, Node.js, Express.js, AWS. Like this and complete. Very good. So, you have also learned to handle this. It must have been a little complex. Recap it again and see. Obviously it is a recorded video. This is the benefit you have. Alright. Shall we move ahead? We can definitely move ahead. Instead of inline JSX, create a reusable component. Now you know how to work by making a component. You know, right? I have told you. I have told you in 2-3 projects. If you say that you don't know by making components, although all these things which I have just told you, that too will be your practice. Because I have already explained in projects. I have explained in a little depth. So now let's see once how to work by making components. But you first do it yourself. Then see. So here, now let's assume this same one, Array of object. We have to work on this and create a user card. We are getting one user, so we have to create a user card and work on it. Alright, let's do it. First of all, we have to map it. We have to map it. We have created braces. Array.map. And we have given a function like this. By default, you will get two or three parameters. Two of the most useful. The third parameter is your array. If you don't know, I will tell you. The third parameter is your array. So, here you have the first item and each item is an object or user. So, I am giving the name of the user here. You can give any name, it will be an object, keep this in mind. And let's take the index too. And there is no need to take the index here because we have given the ID inside the user. But the ID is the same, we will have to separate the ID here. If you have an ID from the database, then the ID is always unique. So you can also give ID instead of key. So this is done and we have used the syntax of curly braces. If you have used curly braces, then you have to return here. Ok. And here our div has come like this. And here we will give key. What will we give in key? ID. Where is ID coming? In the user object. So how will we access? User.id. Ok. Very good. But we don't have to do it this way. We have to make a component and use it. So, let's make a component. Let's give the name of the component as userCard.jsx. So, we will render this userCard and not div. What will we render? UserCard. We will render this userCard. Why are we getting userCard 5 times? Because we have 5 objects. There are 5 objects so the loop is running 5 times. Close it for now. It is working 5 times. Very good. Let's reload. This is coming. And key, again you have to give. So here you can pass the key in this way in the component. Key does not go as a props. If you are passing the key, then it is not going as a props. You will feel that you are passing as a props but it does not go as a props. Now I will show you by doing it. What will you give in the key? User.id. Very good. You will feel that something is coming to us here. Props. So let me show you what is coming to you. Let's do CLG. Props. And see here, it is empty. You have passed the key, but it is working as a separate key. It is not working as a props. Actually, it is working as a key to identify uniquely. It does not work as a props. So, if you are giving a key name here, then think before giving a name. Okay. Do not give the name of props as key. Okay. The key of props, actually, it is also called key. Key and value. So, do not give the name of this as key. If you want to consider it as props. And if you want to identify it uniquely, then definitely you will give a key. Now whatever you have to do in the user card, do it. Where will this data be found in the user card? Data will work only if it is found. So send the data. Here is the user. One object is coming. Send this as it is object here. You can send it. Give the user a key. and user in data. Pass this user here. You can give any key here. User details, user, whatever you give here, you have to destructure it with the same name. These are all props that I have told you earlier. So, it's your choice. I will give user details only. User details. So, you must be getting these user details here. Wait a minute. Oh, man. It's control shift T, right? Okay. So, you must be getting user details in props. Basically, you must be getting object. Look. Props is definitely an object. Now in that object, you are getting things that you have sent. So what you have sent is user details. That's why you are getting user details. Let's remove user details if you are feeling confused. I will send you different things. Like I am sending name here. Minus. And I am sending age. 21 like this. So now you will see what is coming here. This is an object. The key value pair that you send here becomes an object. You are getting each object. Name, age. How will you access here? props.name, props.name, props.age. Do you understand? So, whatever key you are sending here, you access it with dot notation. If you don't want this, then you can destructure it here. What did you send? You sent name and age. So, here we have destructured name and age. Good? Okay. Do you understand this much? I have already told you this, but I don't know. I will explain it again. So, you are getting name and age. You can see by doing CLG. Name, age. Okay. Let's reload. You are getting name and age. Do we need the name edge? No, we need the user details. So, we will end with user details. Where is the user details? Here it is. We have mapped it. We are getting the user details. We are getting the object of each user. Now, what do we have to take here? User. Do we have to write user? No, no. We have to write user details. We have to write the name of the key. This is the key, right? User details. Here, user details. Now, you can see here that you are getting the object of each user details. Look carefully. 1st object, 2nd object, 3rd object, 4th object. So, ID is name and age. So, simply show ID, name, age. Here you have ID. UserDetails.id And then you have here UserDetails.name And then you have here UserDetails.age That's it. See this. Now you will simply change it to a user card and it will automatically work. For example, I will give class name as BG Tomato and margin as 5 so that there will be some spacing. Now you have a card. Now you keep on styling it and it will be fine. That's it, your work is done. You have done proper mapping. If you want to change it in data, then come here and change it. If you want to change it in data, you will change it here and automatic data will be changed. If you want to change it in UI, change it in the card and UI will be changed. Because mapping is done. Mapping is very interesting. Did you understand this much? And if you didn't, then recap it quickly. So rendering components with dot map. Conditional rendering with mapping. Now, conditional rendering, just, our previous project was based on conditional rendering. I gave you two tasks, you must have done it, I also told you. Before that, our lecture was on conditional rendering. If you are not watching it in sequence, then watch it. So, I told you conditional rendering, how you can do it. Like, here we have to put condition. Here you have age, right? See, you have age, so assume here is 21, here is 19, here is 17 age, and here you have some, 15 and here you have 22. Ok, change the name also. Let's change it to Gabbar. Let's change it to Babita. And let's do something here. What should we do? Let's change it to Roald. Very good. I have given any name. So, now let's assume that we have to put a condition that if our age is more than 18, The user whose age is more than 18 should be visible. Now all the users are visible here. Here all the users are visible. If you see here, 21, 19, 17, 15, 22 are visible. So, I want those whose age is more than 18 to be visible. So, I will put a condition here. If our user.age object hai, to user.age agar maa greater than 18 hai, tabhi aap ye wala component render karna, otherwise mat karna, bataya tha na maine, and operator kis tarike se kaam karta, agar ye aapka truthy value hai, tabhi aapka ye wala return ho raha hoga, that means, agar ye wala condition true hai, tabhi aapka ye return ho raha hoga, otherwise nahi ho raha hoga, So here each user will come and check if the user's age is greater than 18. The card of the user whose age is greater than 18 will be rendered here otherwise it will not be done. Now if you come here and see, you are getting only 3 cards here and see it is not scrolling here. You are getting only 3 cards 21, 19, 22. The one less than 18 has disappeared. So this way you can do conditional rendering. There are more things here, for example, I will replicate this, I will comment it. And remove this. Here I have told you about the ternary operator. So you can do all that work here. So not here, basically inside the user card. You can do it here. As the name is written here, I have taken an example here instead of the name. You can see in the code or there is an example in the notes. If age is greater than 18, then show the name. Otherwise, show too young. So I can also do conditional rendering here. If userDetails.age is greater than 18, this is not the part of this lecture, it is the part of conditional rendering. So I want to do something, otherwise here I I want to show too young. If our age is greater than 18, if it is true, then our first one works here. And if it is false, then our second one works here. So, if age is greater than 18, then our name will be visible here. Otherwise, we will see too young. Okay, this time we have not removed it. This time we have shown all, but conditionally. Here, look, Manish Kumar Lal is visible, here Muskaan is visible, here too young is visible. Whereas the name was there, but too young is visible because he is younger than 18. Here you can see 2 young because it is smaller than 18. Here you can see actual name of joker world because it is bigger than 18. So you can do conditional rendering like this along with mapping. So I believe you must have done your practice that's why I have taken this. You must have enjoyed it. And now you can see the common beginner mistakes. The first mistake is the curly braces one which I have told you. If you are using curly braces, then it is very important to return it. See, the first one is wrong. If you write like this, then it is wrong. What it has done here is that it has used curly braces and has not returned it. So, definitely, will it be rendered? It will not be rendered. Here we have not used curly braces. You can use parenthesis here for readability. But they have not used parenthesis. So, they have not used curly braces so it will return. Here we have used curly braces and also returned. If you will use curly braces then it is important to return. If you will not use then there is no need to return. Okay. The second mistake is that you are not passing the key. Okay. Not using key prop. So, you have to give the key prop. Okay. Whatever you have made, you have to give the key prop. Otherwise, it will not be able to identify uniquely. And here, there is another mistake that people also start understanding like actual props. That if you send key in card or component, then props will go. Props are not going like this. All right. Then the third mistake is mutating the original array before mapping. In the original array, you don't have to mutate. Keep a little focus on mutability. You don't have to mutate. Keep a little focus on mutability. Mutate means you don't have to change in the original array. Without changing. If you want to change, then make a copy and change. You don't have to change in the original array. All right. 4th mistake is returning multiple root elements inside. map without wrapping react fragment. This means if you have mapped all the items then you are returning multiple elements. You have returned h1 as well. This is a normal game of react. You have returned div as well. So, you can't do this. You can return only one element at a time. So, definitely wrap it in the fragment. If you want to return multiple elements, then either wrap it in the fragment or in the div. In total, you have to return one element, not multiple. If you want to do multiple, then either wrap it in the div or in the fragment. Okay. So, these were small mistakes. Which definitely you will not do. I hope so. Rest, you will definitely do if you don't practice. If you are practicing, then definitely you will not make these mistakes. And thank you very much. That's all for now. And did I have to say anything else? Yes, I had to say. I had to say that you are watching the videos regularly. But now again the videos are going to be a little irregular. If the festival is coming, then definitely I will go home. So definitely your videos will not be able to come between Diwali and Chhatt. So, don't worry if it's stopped, if this react is completed or anything. I'll post a video that if videos don't come there, then what do you have to do? I'll give you some tasks. Till then, you have to go. That's also important, right? You can't just do this. You have to see all the things. So, that's my helplessness that I'm taking leave from Diwali to Chhatt. So, definitely, you can see. Okay. Rest, I'll give you an update. Because it must have been fun in yoga lecture. That's all for now. See you in the next lecture. And till then, keep exploring. Encode. Bye-bye.
