E-Plant Shopping
An early Redux Toolkit project that connects a plant catalog and shopping cart, using shared state for item quantities, removals, and price totals.

E-Plant Shopping (IBM Course Project)
I built this plant shopping app while learning React and Redux in an IBM course. It's a plant store where users browse plants by category, add them to a cart, and adjust quantities or remove items. All cart state is managed with Redux Toolkit.
Redux store
I set up one store with a cart slice, then wrapped the app in a Provider so every component can read the cart.
const store = configureStore({
reducer: {
cart: cartReducer,
},
});<Provider store={store}>
<App />
</Provider>Cart slice (reducers)
The slice has three reducers: add, remove, and update quantity. Redux Toolkit uses Immer, so I could write existingItem.quantity++ directly instead of copying the state.
reducers: {
addItem: (state, action) => {
const { name, image, cost } = action.payload;
const existingItem = state.items.find(item => item.name === name);
if (existingItem) {
existingItem.quantity++;
} else {
state.items.push({ name, image, cost, quantity: 1 });
}
},
removeItem: (state, action) => {
state.items = state.items.filter(item => item.name !== action.payload);
},
updateQuantity: (state, action) => {
const { name, quantity } = action.payload;
const itemToUpdate = state.items.find(item => item.name === name);
if (itemToUpdate) {
itemToUpdate.quantity = quantity;
}
},
},If a plant is already in the cart, adding it again increases the quantity instead of creating a duplicate.
Connecting components with hooks
The product list dispatches addItem when a user clicks "Add to Cart":
const handleAddToCart = (product) => {
dispatch(addItem(product));
setAddedToCart((prevState) => ({ ...prevState, [product.name]: true }));
};The cart reads items with useSelector and handles quantity changes. Decreasing from 1 removes the item:
const cart = useSelector(state => state.cart.items);
const handleDecrement = (item) => {
if (item.quantity > 1) {
dispatch(updateQuantity({ name: item.name, quantity: item.quantity - 1 }));
} else {
dispatch(removeItem(item.name));
}
};Prices are stored as strings like "$15", so I parse them before calculating totals:
const calculateTotalCost = (item) => {
const unitPrice = parseFloat(item.cost.substring(1));
return unitPrice * item.quantity;
};What I learned
- Managing global state with Redux Toolkit (
configureStore,createSlice) - Writing reducers and dispatching actions with
useDispatchanduseSelector - Rendering lists and handling cart logic like duplicates, quantity changes, and removal
- Structuring a multi-view React app (plant list, cart, about page)
Bugs I noticed in the repo
While reading the code, I found two things worth fixing before you show this off:
calculateTotalAmountinCartItem.jsxis missing areturn, so the total shows empty:
const calculateTotalAmount = () => {
return cart.reduce((sum, item) => sum + parseFloat(item.cost.substring(1)) * item.quantity, 0);
};ProductList.jsx uses useDispatch() but doesn't import it, which would crash the page. Add import { useDispatch } from 'react-redux';.