- Building a Complete Project From the Ground Up
- Building & Configuring Components
- Using State & Context
- Managing HTTP Requests & Side Effects
- Use the starting project attached to this lecture
- Add components for displaying products, the cart (in a modal) and a checkout form (also in a modal)
- Fetch the (dummy) meals data from the backend & show it on the screen (Get /meals)
- Allow users to add & remove products to / from the cart
- Send cart data along with user data (full name, email, street, postal code, city) to the backend (POST /orders)
- Handle loading & error states
- run
npm install
in thebackend
folder - run
npm install
in the main project folder (frontend) - run
npm start
in thebackend
folder - run
npm run dev
in the main project folder (frontend) - create a
README.md
file
- add a
components
folder - inside of it, add a
Header.jsx
file - use this header in the
App.jsx
component
- add a new
Meals.jsx
component - send a GET HTTP request to the dummy backend from inside
Meals.jsx
- output the meals items (just the names for now) from inside
App.jsx
- add a
MealItem.jsx
file - output the
<MealItem>
component inMeals.jsx
- prepend the image source data in
MealItem.jsx
to load the images from the backend
- add a new
util
folder & add a newformatting.js
file inside it for formatting the price - use the
currencyFormatter
function inMealItem.jsx
- add a
UI
subfolder inside thecomponents
folder for UI core generic building blocks - add a new
Button.jsx
inside thatUI
folder - use this
<Button>
component in your app, for example:- a text only button style in the
Header.jsx
component - an other button style in the
MealItem.jsx
component
- a text only button style in the
- use React's context feature to manage the cart data in a more general centralized way
- add a
store
folder - inside it, add a
CartContext.jsx
file where you manage this cart data & this cart context
- add a
- use React's Reducer feature instead of State
- finish the cart logic inside the
cartReducer
function inCartContext.jsx
- connect the cart logic with help of
useContext()
to the different components- use the
useReducer()
hook correctly inside of theCartContextProvider
component - pass the cart context value to the
<CartContext.Provider>
component
- use the
- use the cart context inside of the other components
- wrap all your components with the
<CartContextProvider>
component inApp.jsx
- use the cart context in
MealItem.jsx
to update your cart - access the cart context in
Header.jsx
to display the number of meals in the cart
- wrap all your components with the
- build a modal as a standalone reusable UI component named
Modal.jsx
- use an
open
prop &useEffect()
&useRef()
to open this dialog
- add a new
Cart.jsx
component for outputting the cart data on the screen - use
useContext()
to get access to the cart items stored in the cart context - add a new
UserProgressContext.jsx
component for taking care of showing or not showing this cart data - use the
UserProgressContextProvider
inApp.jsx
and wrap it around the other components - use the
UserProgressCtx
inHeader.jsx
- show the Cart component in
Cart.jsx
with help ofuseContext()
- output the
<Cart>
component inApp.jsx
- set the logic for closing the modal in
Cart.jsx
&Modal.jsx
- add a new
CartItem.jsx
- output the
<CartItem>
component inCart.jsx
- make sure the buttons increase & decrease the items quantity in the cart
- show the
Go to Checkout
button only if we have an item in the cart inCart.jsx
- add a new
Checkout.jsx
component that will show a new page when clicking on theGo to Checkout
button - it should open a modal
- create a new shared
Input.jsx
component - manage opening & closing the modal
- output the
<Checkout>
component inApp.jsx
to show the checkout modal - update the
UserProgress
context whenever the dialog is closed withescape
by adding anonClose
prop inModal.jsx
- use the
onClose
prop inCart.jsx
&Checkout.jsx
- handle form submission in
Checkout.jsx
- validate the input in
Input.jsx
with help of therequired
attribute - get hold of the entered values with the built-in
FormData
feature inCheckout.jsx
- send the POST request inside the
handleSubmit
function inCheckout.jsx
- make some order on the app & check the
orders.json
file to see whether the order was sent successfully
- create a new
hooks
folder & add a newuseHttp.js
file inside of it - define a new
sendHttpRequest
helper function - define another new
sendRequest
function inside of theuseHttp
custom hook function - use
try / catch
- manage some state to reflect those different requests states in the UI
- use the
useHttp
custom hook inMeals.jsx
- add a new
Error.jsx
component to output some error message - add CSS styles for loading & error messages in
index.css
- use the
useHttp.jsx
hook component inCheckout.jsx
- handle the
data
,isLoading
&error
states - clear the cart once submitted the order in
Checkout.jsx
with help of a newclearCart
function defined inCartContext.jsx
- clear the data after submitted a successful order with help of a new
clearData
function inuseHttp.js
& call it inCheckout.jsx