@umbraco-cms/backoffice

    Function appendToFrozenArray

    • Function

      appendToFrozenArray

      Type Parameters

      • T

      Parameters

      • data: T[]

        An Array which is frozen and should be updated.

      • entry: T

        A new entry to append to the array.

      • OptionalgetUniqueMethod: (entry: T) => unknown

        Method to retrieve a value of an entry that is unique to it. This enables the method to replace existing value if it matches the unique value.

      Returns T[]

      • Returns a new array with the new entry appended.
      • Inserts or replaces an entry in a frozen array and returns a new array.

      Example: Example append new entry for a UmbArrayState or a part of UmbObjectState/UmbDeepState which is an array. Where the key is unique and the item will be updated if matched with existing.

      const entry = {id: 'myKey', value: 'myValue'};
      const newDataSet = appendToFrozenArray(myState.getValue(), entry, x => x.id === id);
      myState.setValue(newDataSet);
    MMNEPVFCICPMFPCPTTAAATR