@jiminp/tooltool
    Preparing search index...

    Function recordAccess

    • Accesses a nested record at the given path, returning both the current value and a setter function.

      Type Parameters

      • T = unknown

        The type of the value to be accessed.

      Parameters

      • obj: Record<string, unknown>

        The nested record to access

      • ...path: (string | string[])[]

        An array of strings representing the path to the desired value

      Returns [T | undefined, (value: T) => void]

      A tuple containing:

      • value: The value at the path, or undefined if the path does not exist
      • setValue: A function that sets a new value at the path, creating intermediate objects as needed
      const obj = { a: { b: { c: 42 } } };
      const [value, setValue] = recordAccess<number>(obj, ['a', 'b', 'c']);
      console.log(value); // 42
      setValue(100);
      console.log(obj.a.b.c); // 100