I am using .map to go through data inside of an array. And I want to style each "bundle of data" seperately. I have multiple sections (Appetizers, Lunch, etc) each section has its own items. How can I seperate each menu item into its own box.
import data from "../data";
import "./Food.css"
const Food = () => {
return (
<div> <h2 class ="AppHead">Appetizers</h2>
<div class = 'box'>
{data.appetizers.map((food) => {
return (
<div>
<div class ="">{food.name}</div>
{food.price}
{food.description}
{Math.floor(Math.random() * 10000)}
</div>
)
})}
</div> </div>
);
};
export default Food;
This is what I want to recreate
This is the code
I want to recreate that image with CSS.
2
Answers
Here is a simple example of how you can accomplish this. You can have your parent data that will look something like this:
Ideally I would recommend making each section their own component. So you could have an Appetizers component where you would pass data.appetizers as a prop where you can then display the data with whatever styling you want. Then do the same for Lunch, Dinner, etc.
That would look something like:
then do whatever styling you want in your css file and it should apply to each rendered menu Item. I think that is what you want to achieve.