1

So, I have a dictionary with keys and an array of Objects as values for each key. What I need to do is render a new component with props coming from Object for each element of the array. This is how the it looks.

    1:
       [
         Object {
                  "ClassId":232,
                  "Teacher":"TeacherName"
                   ...
                }
        Object {
                  "ClassId":21,
                  "Teacher":"TeacherName"
                   ...
                }
        ...
        ]

This is the code I have right now but somehow the component does not render to the screen.

timetable[key]["value"]. The value field is there because the actual value for a key is another dictionary, but I'm only using the value. Printing the elements in the console instead of passing them as props to the CourseCard component looks good, the data is there.

       {Object.keys(timetable).map((key, index) => {
                    timetable[key]["value"].map(iter => {
                      return (
                        <CourseCard
                          teacher={iter["Teacher"]}
                          course={iter["ClassName"]}
                          classRoom={iter["ClassRoom"]}
                          time={iter["Time"]}
                          key={iter["Key"]}
                        />
                      );
                    });
                  })}

1 Answer 1

10

You need to return the result of inner map function,

   {Object.keys(timetable).map((key, index) => {
                return timetable[key]["value"].map(iter => {
                  return (
                    <CourseCard
                      teacher={iter["Teacher"]}
                      course={iter["ClassName"]}
                      classRoom={iter["ClassRoom"]}
                      time={iter["Time"]}
                      key={iter["Key"]}
                    />
                  );
                });
              })}
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! It renders now, it puts some extra info in there but I can manage that. Thank you very much!!
@RadulescuPetru, glad it helped

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.