0

I have been trying to render the P_words list element word with react using map:

const f_data = {
key: 2412,
reviewed: 100,
rating:4,
P_words: [{
    word: "Coolx",
    freq: 5
},
{
    word: "Dumbf",
    freq: 6
}

]

So this is the code inside my function to render this list:

          <ul>
        Cool
        {f_data.P_words.map((obj) => {
          <li key={obj.freq}>{obj.freq}</li>;
        })}
      </ul>

I checked the DOM it shows cool but it shows a empty ul tag. Sorry if this is kind of vague.

1
  • Not related but suggest to use obj.word as your unique key. Commented Jul 8, 2021 at 18:27

2 Answers 2

4

You're missing a return from .map, if you choose to use curly braces, you need to explicitly return something

      <ul>
        Cool
        {f_data.P_words.map((obj) => {
          return <li key={obj.freq}>{obj.freq}</li>
        })}
      </ul>

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

Comments

0

You can try directly using parethesis:

<ul>
        Cool
        {f_data.P_words.map((obj) => (
          <li key={obj.freq}>{obj.freq}</li>;
        ))}
      </ul>

Because it miss the return

Comments

Your Answer

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