From the course: React: Design Patterns

Unlock this course with a free trial

Join today to access over 24,700 courses taught by industry experts.

Solution: Recursive folders

Solution: Recursive folders - React.js Tutorial

From the course: React: Design Patterns

Solution: Recursive folders

- [Instructor] Alright, hopefully gave this challenge a try. Let's take a look at the solution. So, first of all, what we wanted to do inside this file tree structure was take the remaining structure, right? This could really be any substructure as well, right? Each of these children here looks the same, essentially, as the original structure that it belonged to, right? So, what we want to do is we want to take whatever structure we're looking at and really just render sort of the top level, if you will. Alright, so here's what this is going to look like. We're going to, inside this UL, right, this unstructured list, we're going to start off by "saying structure.map". Now, if you realized, down here, structure is always going to be an array because we're going to be just passing this thing as the structure, and then we're going to be passing the children of each structure recursively. And notice that each of those is an array as well, alright? So, structure's always going to be an…

Contents