1

I' have react js project that does the nested rendering. I'm seeing the output on consoles, but no on the web.

<div>
              {Experience &&
                Experience.map((exp) => {
                  return (
                    <div className="text-white">
                      {
                        //Here we loop trough the exp keys
                        Object.keys(exp).forEach((key) => {
                          // console.log("key", key);
                          // console.log("key data", exp[key]);
                          // console.log(exp[key].desc);
                          return (
                            <p
                              dangerouslySetInnerHTML={{
                                __html: exp[key].desc,   //this doesnt display
                              }}
                            />
                          );
                        })
                      }
                    </div>
                  );
                })}
            </div>
5
  • 1
    Can you pls make a screenshot of the logs Commented Sep 9, 2021 at 20:31
  • What is the value of Experience? If this value comes from Firebase, show the code for how you read it and pass it to the rendering, and the data that you're reading from the database. Commented Sep 9, 2021 at 20:37
  • I got it working with Object.keys(exp).map instead of foreach. If this is the data structure of Experience. const Experience = [ { abc: { desc: '<p>abc</p>' }, efg: { desc: '<p>efg</p>' } }, { hij: { desc: '<p>hij</p>' }, klm: { desc: '<p>klm</p>' } } ]; Commented Sep 9, 2021 at 20:53
  • Great to hear it worked out :) Commented Sep 9, 2021 at 20:57
  • Also make sure className="text-white" is not hiding the data because your text is white and background is also white. I hope it's not !! but happened to me as I have bootstrap styles. Commented Sep 9, 2021 at 20:57

1 Answer 1

2

I think this question is more of knowing the diffrence between foreach and map.

That means foreach is not retuning anything and mutating data. If you change your foreach to map, things will work.

map() allocates memory and stores return values. forEach() throws away return values and always returns undefined.

forEach() will allow a callback function to mutate the current array. map() will instead return a new array.

Note: Make sure className="text-white" is not hiding your white text.

Sign up to request clarification or add additional context in comments.

Comments

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.