Preparing search index...
    • React hook for managing ingredient operations in the Recipe screen.

      This hook provides three main operations:

      • editIngredients: Updates an existing ingredient, triggering validation if the name changes
      • addNewIngredient: Adds an empty ingredient row to the form
      • addOrMergeIngredient: Adds a new ingredient or merges quantities if it already exists

      The hook handles the complexity of ingredient validation, fuzzy matching, and duplicate detection. When an ingredient name is changed, it uses the validation queue system to suggest similar ingredients from the database. For duplicate ingredients with matching units, quantities are automatically summed together.

      Returns UseRecipeIngredientsReturn

      Object containing ingredient manipulation functions

      const { editIngredients, addNewIngredient, addOrMergeIngredient } = useRecipeIngredients();

      // Add a new empty ingredient row
      addNewIngredient();

      // Edit an ingredient (triggers validation if name changes)
      editIngredients(0, '200g flour');

      // Add or merge a validated ingredient
      addOrMergeIngredient({
      id: 1,
      name: 'flour',
      quantity: '100',
      unit: 'g',
      season: [],
      type: ''
      });