A component to manage application updates.
npm install react-clear-cache> A component to manage application updates.
 

- Fetched on window focus
- Stop fetching on window blur
See demo
``bash`
$ npm install --save react-clear-cache
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"
}
`tsx
import * as React from 'react';
import { ClearCacheProvider, useClearCacheCtx } from 'react-clear-cache';
const App: React.FC<{}> = () => {
const { isLatestVersion, emptyCacheStorage } = useClearCacheCtx();
return (
href="#"
onClick={(e) => {
e.preventDefault();
emptyCacheStorage();
}}
>
Update version
ReactDOM.render(
document.getElementById('root')
);
`
`tsx
import * as React from 'react';
import ClearCache from 'react-clear-cache';
const App: React.FC<{}> = () => {
return (
href="#"
onClick={(e) => {
e.preventDefault();
emptyCacheStorage();
}}
>
Update version
export default App;
`
`tsx
import * as React from 'react';
import { useClearCache } from 'react-clear-cache';
const App: React.FC<{}> = () => {
const { isLatestVersion, emptyCacheStorage } = useClearCache();
return (
href="#"
onClick={(e) => {
e.preventDefault();
emptyCacheStorage();
}}
>
Update version
export default App;
`
You can set the duration when to fetch for new updates.
Set to true to auto-reload the page whenever an update is available.
A boolean that indicates whether the request is in flight
A boolean that indicates if the user has the latest version.
This function empty the CacheStorage and reloads the page.
1. geminstall23
MIT © geminstall23
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.
If you are done making changes, reset main to dist/index.js` in package.json.