reactiveweb
    Preparing search index...

    Function RemoteData

    json-based remote data utility

    • json-based remote data utility.

      this API mimics the API of fetch, and will give you a reactive [[State]] object, but won't be able to re-fetch when the url or options change

      import { tracked } from '@glimmer/tracking';
      import { use } from 'ember-resources';
      import { RemoteData } from 'reactiveweb/remote-data';

      class Demo {
      @use myData = RemoteData(`https://some.domain.io`);

      @use withOptions = RemoteData(`https://some.domain.io`, {
      headers: {
      Authorization: 'Bearer <token>'
      }
      });
      }

      In strict mode with <template>

      import { RemoteData } from 'reactiveweb/remote-data';
      
      const options = (token) => ({
        headers: {
          Authorization: `Bearer ${token}`
        }
      });
      
      
      

      Type Parameters

      • T = unknown

      Parameters

      • url: string
      • Optionaloptions: RequestInit

      Returns State<T>

    • json-based remote data utility

      For a reactive URL (causing the underlying fetch to re-run when the URL changes), the url must be the return value from a function passed to RemoteData.

      import { tracked } from '@glimmer/tracking';
      import { use } from 'ember-resources';
      import { RemoteData } from 'reactiveweb/remote-data';

      class Demo {
      @tracked url = 'https:// .... '

      @use myData = RemoteData(() => this.url);
      }

      Type Parameters

      • T = unknown

      Parameters

      • url: () => string

      Returns State<T>

    • json-based remote data utility

      When you want the remote data request to re-fetch when either the URL or FetchOptions change, the url becomes a property on the object returned from the thunk.

      import { tracked } from '@glimmer/tracking';
      import { use } from 'ember-resources';
      import { RemoteData } from 'reactiveweb/remote-data';

      class Demo {
      @tracked id = 2;
      @tracked postData = '';

      @use myData = RemoteData(() => ({
      url: `https://this.some.domain/${this.id}`,
      method: 'POST',
      body: this.postData
      }));
      }

      Type Parameters

      • T = unknown

      Parameters

      • options: () => { url: string } & RequestInit

      Returns State<T>