From the course: Master Next.js: Elaborate Hands-On Web Development, React Basics, Advanced Next.js, and Deployment
Unlock this course with a free trial
Join today to access over 25,200 courses taught by industry experts.
Mapping through lists in React
From the course: Master Next.js: Elaborate Hands-On Web Development, React Basics, Advanced Next.js, and Deployment
Mapping through lists in React
All right, so we now have this cool customizable header. We can actually have multiple headers now that can have their own types of customization, right? I created another header that has another title, and this title could be super cool. And instead of just restricting all the headers to equal I love React, we can just check to see if the title exists, otherwise we throw an error. So we can just say if the title exists, then title, otherwise title not found. And if we go to Chrome and we refresh now, we're going to see that we're getting multiple titles. This would be silly error handling in this context now that we switched it, because if you have multiple titles and then a title is not found, and you're getting error for a title not found, it's not going to make sense if you have multiple titles, if you're just checking the title. What you'd want to do, meaning if I remove this header, if I remove the title from the second header property and I refresh, we're gonna get this error…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.