# react-clear-cache

> A component to manage application updates.

Latest version **1.4.14** (published 2023-01-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-clear-cache
pnpm add react-clear-cache
yarn add react-clear-cache
bun add react-clear-cache
```

Provides the command `generate-build-meta`.

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.4.14 |
| Published | 2023-01-26 |
| First published | 2019-06-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=8 |
| Dependencies | 3 |
| Unpacked size | 88.2 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 67 |
| Author | geminstall23 |
| Maintainers | nucab |

## Links

- npm: https://www.npmjs.com/package/react-clear-cache
- Repository: https://github.com/geminstall23/react-clear-cache
- Homepage: https://github.com/geminstall23/react-clear-cache#readme
- Issues: https://github.com/geminstall23/react-clear-cache/issues
- npm.io page: https://npm.io/package/react-clear-cache

## Dependencies (3)

- [uuid](https://npm.io/package/uuid.md) ^3.3.2
- [minimist](https://npm.io/package/minimist.md) ^1.2.5
- [use-persisted-state](https://npm.io/package/use-persisted-state.md) ^0.3.0

## Recent versions

- 1.4.14 (latest) — 2023-01-26
- 1.4.13 — 2023-01-26
- 1.4.12 — 2020-12-28
- 1.4.11 — 2020-12-15
- 1.4.10 — 2020-12-05
- 1.4.9 — 2020-12-05
- 1.4.8 — 2020-12-01
- 1.4.7 — 2020-12-01
- 1.4.6 — 2020-12-01
- 1.4.5 — 2020-12-01
- 1.4.4 — 2020-12-01
- 1.4.3 — 2020-11-18
- 1.4.2 — 2020-11-18
- 1.4.0 — 2020-11-18
- 1.3.2 — 2020-08-18
- … 33 more at https://npm.io/package/react-clear-cache/versions

## README

# react-clear-cache

> A component to manage application updates.

[![NPM](https://img.shields.io/npm/v/react-clear-cache.svg)](https://www.npmjs.com/package/react-clear-cache) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

[![Rate this package](https://badges.openbase.com/js/rating/react-clear-cache.svg?token=wqFZAY/V6KcfoKNmFEUlKWwXKAqWXg9RRKz2eE8fXqg=)](https://openbase.com/js/react-clear-cache?utm_source=embedded&utm_medium=badge&utm_campaign=rate-badge)

## Demo

- Fetched on window focus
- Stop fetching on window blur

## Demo

See [demo](https://geminstall23.github.io/react-clear-cache/)

## Install

```bash
$ npm install --save react-clear-cache
```

## Add script in package.json

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

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

## Usage

### Using `Context API`:

```tsx
import * as React from 'react';

import { ClearCacheProvider, useClearCacheCtx } from 'react-clear-cache';

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

ReactDOM.render(
  <ClearCacheProvider duration={5000}>
    <App />
  </ClearCacheProvider>,
  document.getElementById('root')
);
```

### Using `render props`:

```tsx
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`:

```tsx
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.

### `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. [geminstall23](https://github.com/geminstall23)

## License

MIT © [geminstall23](https://github.com/geminstall23)

## 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.

---
_Source: https://npm.io/package/react-clear-cache · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
