easy-cache-react

Modern, tested and fully written in typescript.

Usage no npm install needed!

<script type="module">
  import easyCacheReact from 'https://cdn.skypack.dev/easy-cache-react';
</script>

README

Easyblue

Lines npm npm github release github issues github closed issues

easy-cache-react

Modern, tested and fully written in typescript.

Written here at easyblue.io, a french insurtech company. Check out our website to see how we're using this package in production.

Installation

yarn add easy-cache-react or npm install easy-cache-react

Basic Usage

useEasyCache hook

import * as React from 'react';
import { useEasyCache } from 'easy-cache-react';

import packageJson from '../package.json';

const App: React.FC = () => {
  const { loading, isUpToDate } = useEasyCache(packageJson.version, 1000);

  if (loading) {
    return <>Your App is loading...</>;  
  }

  if (!isUpToDate) {
    return <>A newer version of your app is available, you will be redirected soon...</>;
  }

  return (
    <div>
      Your awesome App
    </div>
  );
};

export default App;

Your App need to expose a meta.json file (customisable) containing the current production version.

Full API

export type EasyCacheHookType = {
  loading: boolean;
  isUpToDate: boolean;
  error: Error | null;
};

export function useEasyCache(
  packageJsonVersion: string,
  timeout: number = 0,
  onCacheReload: () => void = () => window.location.reload(true),
  metaPath: string = '/meta.json',
  resolver?: ReleaseResolverType
): EasyCacheHookType;