Nutrition Calculator
The Nutrition Calculator computes real-time nutrition, allergens, and match status for customizable dishes as the diner makes selections.Use Case
For “Build Your Own” dishes like stir-fries or salads, nutrition depends on what the diner chooses:- Base: Brown Rice vs Egg Noodles vs Kale
- Protein: Chicken vs Tofu vs Shrimp
- Sauce: Coconut Curry vs Garlic Butter vs Sesame

Getting Customization Options
First, fetch the dish’s customization options:Example Response
Calculating Nutrition
As the diner makes selections, call the nutrition calculator:Selection Input
Real-Time Updates

| Selection | Calories | Match Status |
|---|---|---|
| (none) | 120 | Unknown |
| Brown Rice | 120 | Match (Vegan, GF) |
| Egg Noodles | 180 | Partial Match (has Egg) |
| + Shrimp | 340 | Not a Match (Shellfish) |
Implementation Pattern
Match Status Updates
The calculator returns updated match status based on selections:Add to Cart
Include selections when adding to cart:Best Practices
Debounce calculations
Debounce calculations
If multiple selections can change rapidly, debounce the calculation call to avoid excessive API requests.
Show loading state
Show loading state
Display a subtle loading indicator on the nutrition panel while recalculating.
Highlight changes
Highlight changes
When nutrition values change, briefly highlight them to draw attention to the update.
Validate required selections
Validate required selections
Check that all required groups have selections before allowing “Add to Cart”.
Show allergen warnings
Show allergen warnings
If a selection adds an allergen that conflicts with preferences, show a clear warning.