0

I have a react return like so:

return (
    <div className="App">
      {data && (
        <div>
            {data.map((d) => {
              return (
                <div key={d.id}>
                  <div>{d.string}</div>
                  <div> {d.array.map((el) => {
                        <div>{el}</div>
                  })}
                  </div>
                </div>
              );
        </div>
      )}
    </div>
  );

Each {el} doesn't render but the array exists, if I try and render {d.array[0]} the first index of the array is rendered, so I'm not the issue. I don't get an error and nothing breaks. Is it a react issue or a javascript issue, or is my syntax wrong.

2 Answers 2

1

You need to add a key to each children of your second map so React knows each one is different:

return (
<div className="App">
  {data && (
    <div>
        {data.map((d) => {
          return (
            <div key={d.id}>
              <div>{d.string}</div>
              <div> {d.array.map((el, index) => {
                    return <div key={index}>{el}</div>
              })}
              </div>
            </div>
          );
    </div>
  )}
</div>
);
Sign up to request clarification or add additional context in comments.

1 Comment

still renders nothing
1

before the "=>" of second map, will have use "()" and not "{}", because all that be in {is js}, and in (jsx).

1 Comment

can you explain that more?

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.