INNER CODE UNIT · TypeScript

setValueAtSegments

margelo/react-native-runtimes · packages/state/src/index.ts:334

function setValueAtSegments<TState>(
  state: TState,
  segments: readonly string[],
  value: unknown,
): TState {
  if (segments.length === 0) {
    return value as TState;
  }

  const [segment, ...rest] = segments;
  const current =
    state != null && typeof state === 'object'
      ? (state as Record<string, unknown>)[segment]
      : undefined;
  const nextValue = setValueAtSegments(current, rest, value);
  const nextState = Array.isArray(state)
    ? [...state]
    : { ...((state ?? {}) as object) };

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…