
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
react-clear-cache
Advanced tools
A component to manage application updates.
See demo
$ npm install --save react-clear-cache
This will generate meta.json
file. This will have the version key with the latest build.
{
"prebuild": "npm run generate-build-meta",
"generate-build-meta": "./node_modules/react-clear-cache/bin/cli.js"
}
Context API
: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')
);
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;
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;
duration
: numberYou can set the duration when to fetch for new updates.
auto
: booleanSet to true to auto-reload the page whenever an update is available.
loading
: booleanA boolean that indicates whether the request is in flight
isLatestVersion
: booleanA boolean that indicates if the user has the latest version.
emptyCacheStorage
: () => voidThis function empty the CacheStorage and reloads the page.
MIT © geminstall23
In package.json, set main
to src/index.js
.
Run npm start
in root directory. It will build and watch if there are changes made.
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.
FAQs
A component to manage application updates.
We found that react-clear-cache demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.