Preparing search index...

    Function useRecipeIngredients

    • 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
      • 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, addOrMergeIngredient } = useRecipeIngredients();

      // 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: ''
      });