update
Updates a value in an interaction object using a transformation function.
Import
You can import the entire package and access the function:
_10import * as sdk from "@onflow/sdk"_10_10sdk.update(key, fn)
Or import directly the specific function:
_10import { update } from "@onflow/sdk"_10_10update(key, fn)
Usage
_16import { update, put, initInteraction } from "@onflow/sdk"_16_16const interaction = initInteraction();_16_16// Set initial value_16put("counter", 0)(interaction);_16_16// Increment counter_16const increment = update("counter", (current) => (current || 0) + 1);_16increment(interaction); // counter becomes 1_16increment(interaction); // counter becomes 2_16_16// Update array_16put("tags", ["flow", "blockchain"])(interaction);_16const addTag = update("tags", (tags) => [...(tags || []), "web3"]);_16addTag(interaction); // tags becomes ["flow", "blockchain", "web3"]
Parameters
key
- Type:
string
- Description: The dot-notation key path to update
fn
(optional)
- Type:
(v: T | T[], ...args: any[]) => T | T[]
- Description: The transformation function to apply to the existing value
Returns
function