1.7.0 • Published 4 years ago

react-clear-cache-path v1.7.0

Weekly downloads
31
License
MIT
Repository
github
Last release
4 years ago

react-clear-cache

A component to manage application updates.

NPM JavaScript Style Guide

Demo

See demo

Install

$ npm install --save react-clear-cache-path

Add script in package.json

This will generate meta.json file. This will have the version key with the latest build.

{
  "postbuild": "npm run generate-build-meta",
  "generate-build-meta": "./node_modules/react-clear-cache-path/bin/cli.js"
}

Custom path where the file will be generated.

{
  "postbuild": "npm run generate-build-meta",
  "generate-build-meta": "./node_modules/react-clear-cache-path/bin/cli.js ./dist/meta.json"
}

Usage

Using render props:

import * as React from "react";

import ClearCache from "react-clear-cache";

const App: React.FC<{}> = () => {
  return (
    <div>
      <ClearCache>
        {({ isLatestVersion, emptyCacheStorage }) => (
          <div>
            {!isLatestVersion && (
              <p>
                <a
                  href="#"
                  onClick={e => {
                    e.preventDefault();
                    emptyCacheStorage();
                  }}
                >
                  Update version
                </a>
              </p>
            )}
          </div>
        )}
      </ClearCache>
    </div>
  );
};

export default App;

Using hooks:

import * as React from "react";

import { useClearCache } from "react-clear-cache";

const App: React.FC<{}> = () => {
  const { isLatestVersion, emptyCacheStorage } = useClearCache();
  return (
    <div>
      {!isLatestVersion && (
        <p>
          <a
            href="#"
            onClick={e => {
              e.preventDefault();
              emptyCacheStorage();
            }}
          >
            Update version
          </a>
        </p>
      )}
    </div>
  );
};

export default App;

Props

duration: number

You can set the duration when to fetch for new updates.

jsonPathFrom: string

You can set the path to get meta.json.

auto: boolean

Set to true to auto-reload the page whenever an update is available.

Render props

loading: boolean

A boolean that indicates whether the request is in flight

isLatestVersion: boolean

A boolean that indicates if the user has the latest version.

emptyCacheStorage: () => void

This function empty the CacheStorage and reloads the page.

Contributors

  1. noahjohn9259

License

MIT © noahjohn9259

Development

  1. In package.json, set main to src/index.js.

  2. Run npm start in root directory. It will build and watch if there are changes made.

  3. cd example and run npm start. It will run the demo application.

Note

If you are done making changes, reset main to dist/index.js in package.json.

1.7.0

4 years ago

1.6.9

4 years ago

1.6.8

4 years ago

1.6.7

4 years ago

1.6.6

4 years ago

1.6.4

4 years ago

1.6.5

4 years ago

1.6.3

4 years ago

1.6.2

4 years ago

1.6.1

4 years ago

1.6.0

4 years ago

1.5.9

4 years ago

1.5.8

4 years ago

1.5.7

4 years ago

1.5.6

4 years ago

1.5.5

4 years ago

1.5.4

4 years ago

1.5.3

4 years ago

1.5.2

4 years ago

1.5.1

4 years ago

1.5.0

4 years ago

1.4.9

4 years ago

1.4.8

4 years ago

1.4.7

4 years ago

1.4.6

4 years ago

1.4.5

4 years ago

1.4.3

4 years ago

1.4.2

4 years ago

1.4.1

4 years ago

1.4.0

4 years ago

1.3.9

4 years ago

1.3.8

4 years ago

1.3.7

4 years ago

1.3.6

4 years ago

1.3.5

4 years ago

1.3.4

4 years ago

1.3.3

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.0

4 years ago