0

I am learning React.js and Redux. I've nested arrays in arrays and mapped them in a table. The code works fine but I want to know if it's good practice or not. Thanks in advance.

return this.props.foodWeekPlan.map((course, i) => {
  return (
    <tr key={i}>
      {course.map((meal, j) => (
        <td key={j}>
          {meal.map((ingredients, k) => (
            <p key={k}>{ingredients}</p>
          ))}
        </td>
      ))}
    </tr>
  );
});

};

1 Answer 1

1

If you want a good practice, try writing a component for each object you mapping then, your code will look something like this:

  return this.props.foodWeekPlan.map((course, i) => <Course key={i} meals={course.meals}/>);
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.