A React application designed to help users build their spacecraft by managing an inventory of essential items. This project demonstrates core React fundamentals, including component-based architecture, state management, handling user inputs with controlled components, and managing interactions between parent and child components.
- Inventory Management: The
SpacecraftBuildercomponent centrally manages the state of the entire inventory. - Item Submission Form: The
ItemFormcomponent provides a user-friendly interface for adding new items to the inventory.- All input fields are required and include client-side validation.
- Missing fields are highlighted on form submission.
- The form clears upon successful item submission.
- Dynamic Inventory Display: The
InventoryDisplaycomponent dynamically renders the current inventory. - Detailed Item Cards: Each item in the inventory is presented as an
ItemCard, showcasing its name, quantity, and purpose. - Item Deletion: The
ItemActioncomponent provides functionality to delete individual items from the inventory. - Parent-Child Communication: Demonstrates robust data flow and state updates using callback functions passed from parent to child components.
The application is structured with a clear component hierarchy:
SpacecraftBuilder(Parent)- Manages inventory state.
- Renders
ItemForm(for adding items). - Renders
InventoryDisplay(for showing and deleting items).
InventoryDisplay(Child ofSpacecraftBuilder)- Receives inventory data as props.
- Renders
ItemCardfor each item. - Renders
ItemActionfor each item (for deletion).
ItemCard(Child ofInventoryDisplay)- Displays individual item details.
ItemAction(Child ofInventoryDisplay)- Provides the delete functionality for an item.
- React: Frontend JavaScript library for building user interfaces.
- Vite: Fast build tool and development server for modern web projects.
- JavaScript (ES6+)
- HTML5
- CSS3
uuidlibrary: For generating unique IDs for inventory items.
Follow these steps to get the project up and running on your local machine:
-
Clone the repository:
git clone [https://github.com/YOUR_USERNAME/your-repo-name.git](https://github.com/YOUR_USERNAME/your-repo-name.git)
(Replace
YOUR_USERNAMEwith your actual GitHub username andyour-repo-namewith the actual name of your repository, e.g.,spacecraft-builder) -
Navigate into the project directory:
cd your-repo-name -
Install dependencies:
npm install
-
Start the development server:
npm run dev
The application should open in your browser, typically at
http://localhost:5173/.
This project is a practical demonstration of several fundamental React concepts:
- Component-Based Architecture: Breaking down the UI into reusable, focused components.
- State Management (
useState): Managing the inventory data and form input values. - Controlled Components: Implementing form inputs where React state is the single source of truth for input values.
- Handling User Input: Capturing and processing input from form fields.
- Form Validation: Implementing client-side validation to ensure required fields are filled and providing visual feedback.
- Parent-Child Component Communication:
- Passing data down via props (e.g., inventory items to
InventoryDisplay). - Passing functions down as callback props to enable child components to trigger state updates in parent components (e.g.,
ItemFormcalling a function inSpacecraftBuilderto add an item,ItemActioncalling a function to delete an item).
- Passing data down via props (e.g., inventory items to
- List Rendering (
.map()withkeyprop): Efficiently rendering dynamic lists of items.
Happy building!