createDataClient()

createDataClient

Params:

  • options: createDataClientOptions
interface createDataClientOptions {
ssr?: boolean;
ssrForceFetchDelay?: number;
fetchPolicy?: 'cache-first' | 'cache-and-network' | 'network-only';
test?: boolean;
initialCache?: Record<string, any>;
headers?: Record<string, string>;
}

Example usage:

import { createDataClient } from 'react-isomorphic-data';
const client = createDataClient({
ssr: false,
});

Configurations

Following is a list of all the fields possible to be configured in the createDataClientOptions object

ssr

  • Type: boolean
  • Default: false

Determines whether the dataClient instance will run on server-side or not.

ssrForceFetchDelay

  • Type: number
  • Default: 0

Determines how many milliseconds the dataClient should prevent client-side refetching on hook/HOC using network-only fetchPolicy.

fetchPolicy

  • Type: 'cache-first' | 'cache-and-network' | 'network-only'
  • Default: 'cache-first'

Determines the how the default fetchPolicy to be used. A more detailed explanation can be found in Caching.

test

  • Type: boolean
  • Default: false

Determines whether the dataClient instance will run in test environment.

initialCache

  • Type: object
  • Default: {}

An object to be used as the client's initial cache. Example usage can be seen in Client-side hydration.

headers

  • Type: Record<string, string>
  • Default: false

Set the default headers that will be included in all other fetch requests. Can be used on server side to forward cookies. Does not work on prefetching due to how <link rel="prefetch"> works.

Last updated on 5/24/2020 by Jacky Efendi