Assignment 1
Assignment 1
Overview
So far, you have learned about the FlatList and SectionList components and how to
render large lists using them. You’ve discovered that while FlatList is useful for
rendering large lists performantly, SectionList adds the ability to separate list items
into sections.
In this assignment, you will expand on the example from an earlier exercise to display
a large list of menu items with each item’s price. You will use the SectionList
component within the Little Lemon app.
By doing this, each menu item will be categorized according to its item type and will
display section headers such as Appetizers, Main dishes and so on.
Scenario
The Little Lemon app needs to display a large list of menu items on the screen, along
with the price of each item, sorted into sections. You have been asked to use the
SectionList component to render these menu items efficiently. Make sure that the
component you write is readable and clean.
Below is the array of menu items, along with the price for each item.
const menuItemsToDisplay = [
{
title: 'Appetizers',
data: [
{ name: 'Hummus', price: '$5.00' },
{ name: 'Moutabal', price: '$5.00' },
{ name: 'Falafel', price: '$7.50' },
{ name: 'Marinated Olives', price: '$5.00' },
{ name: 'Kofta', price: '$5.00' },
{ name: 'Eggplant Salad', price: '$8.50' },
],
},
{
title: 'Main Dishes',
data: [
{ name: 'Lentil Burger', price: '$10.00' },
1
{ name: 'Smoked Salmon', price: '$14.00' },
{ name: 'Kofta Burger', price: '$11.00' },
{ name: 'Turkish Kebab', price: '$15.50' },
],
},
{
title: 'Sides',
data: [
{ name: 'Fries', price: '$3.00', id: '11K' },
{ name: 'Buttered Rice', price: '$3.00' },
{ name: 'Bread Sticks', price: '$3.00' },
{ name: 'Pita Pocket', price: '$3.00' },
{ name: 'Lentil Soup', price: '$3.75' },
{ name: 'Greek Salad', price: '$6.00' },
{ name: 'Rice Pilaf', price: '$4.00' },
],
},
{
title: 'Desserts',
data: [
{ name: 'Baklava', price: '$3.00' },
{ name: 'Tartufo', price: '$3.00' },
{ name: 'Tiramisu', price: '$5.00' },
{ name: 'Panna Cotta', price: '$5.00' },
],
},
];
The screenshots below illustrate how your app should look after you complete this
assignment:
2
The colors displayed in the images above can be applied using the following values:
Starter Code:
You can download the starter code for this assignment, from the zipped folder below:
1_sectionlist---starter-code.zip
Instructions
Step 1: Update MenuItems component to display new list of menu items and use
SectionList
To complete this assignment, you’ll first need to update the MenuItems component
to display the menu items and price.
3
Within this component, use the array provided in this scenario to pass to the data
prop of the SectionList component. Then configure the renderItem prop of the
SectionList component to render each item’s name as well as the price per item.
Hint: You can create multiple components within the same file to keep code clean.
Conclusion
By completing this assignment, you will demonstrate your understanding and ability
to configure and utilize the SectionList component to render a large list of items by
section.