@adobe/data - v0.10.30
    Preparing search index...

    Function withSwitch

    • Dynamically switches between observables in a record based on a key observable. When the key changes, automatically unsubscribes from the previous observable and subscribes to the new one.

      Type Parameters

      • K extends string
      • T extends Record<K, Observe<any>>

      Parameters

      Returns Observe<T[K] extends Observe<U> ? U : never>

      const data = {
      home: homeData$,
      profile: profileData$,
      settings: settingsData$
      };
      const currentTab$ = createState('home');
      const currentData$ = withSwitch(data, currentTab$);
      // When currentTab$ changes, automatically switches to observing the corresponding data observable