15.2.16 Props Exercise
Hello, future software developer! In this exercise, we will practice props in React by creating a spacecraft inventory management system. 🥹
Your mission is to showcase various items aboard a spacecraft, detailing each one's name, type, quantity, and price. But there's a twist! You'll need to implement smart messages within your application: one to warn when any item's stock is running low 🚨 and another to highlight items of high value 💎 that could attract interstellar thieves. This is how it should look:
index.html- Add CDN links for React, ReactDOM, and Babel to enable JSX processing in the browser.
- Add the message, inventory item, and app component files. Be mindful of their import order.
Message.js- Accept
childrenas props and render them as is.
- Accept
InventoryItem.js- Accept
name,type,quantity, andpriceas props. - Set defaults to
quantityandprice. - Render the item's details.
- Render a
Messageif the quantity is below the 5 threshold, indicating low stock. - Render a
Messageif the total value (quantity * price) exceeds the $1000 threshold, suggesting extra protection due to high value.
- Accept
App.js- You are given a list of inventory items. Feel free to change the list.
- Loop through the inventory items and render an
InventoryItemfor each item in the list.
Happy coding!
index.htmlserves as the entry point for the web application. You will load React libraries and link to the React component scripts for in-browser JSX processing.App.jsis the main component that you will use to aggregate the inventory list, renderingInventoryItemcomponents for each item in the inventory.InventoryItem.jsrepresents individual inventory items. You will display their name, type, quantity, and price. You will also conditionally render messages based on stock levels and value.Message.jsdisplays warnings or notifications. You will render the wrapped messages through its children props.
