How to use the react-fetching-library.createCache function in react-fetching-library

To help you get started, we’ve selected a few react-fetching-library examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github marcin-piela / react-fetching-library / examples / cache-provider / src / api / Client.ts View on Github external
import { createClient, createCache, QueryResponse, Action } from 'react-fetching-library';

import { requestHostInterceptor } from './requestInterceptors/requestHostInterceptor';

// In real application this const will be stored in ENV's
const HOST = 'https://private-34f3a-reactapiclient.apiary-mock.com';

const cache = createCache>(
  (action: Action) => {
    return action.method === 'GET';
  },
  (response: QueryResponse & { timestamp: number }) => {
    return new Date().getTime() - response.timestamp < 10000;
  },
);

export const Client = createClient({
  requestInterceptors: [requestHostInterceptor(HOST)],
  cacheProvider: cache,
});
github marcin-piela / react-fetching-library / examples / ssr-nextjs / api / cache.js View on Github external
import { createCache } from 'react-fetching-library';

export const cache = createCache(
  action => {
    return action.method === 'GET';
  },
  response => {
    return new Date().getTime() - response.timestamp < 100000;
  },
);

react-fetching-library

Simple and powerful API client for react. Use hooks or FACC's to fetch data in easy way. No dependencies! Just react under the hood.

MIT
Latest version published 4 years ago

Package Health Score

53 / 100
Full package analysis