react-clear-cache
Advanced tools
Comparing version 1.4.3 to 1.4.4
@@ -10,2 +10,9 @@ import * as React from 'react'; | ||
}; | ||
declare type Result = { | ||
loading: boolean; | ||
isLatestVersion: boolean; | ||
emptyCacheStorage: (version?: string | undefined) => Promise<void>; | ||
} | null; | ||
export declare const ClearCacheProvider: React.FC<OwnProps>; | ||
export declare const useClearCacheCtx: () => Result; | ||
export declare const useClearCache: (props?: OwnProps | undefined) => { | ||
@@ -12,0 +19,0 @@ loading: boolean; |
@@ -1,2 +0,2 @@ | ||
import { useRef, useEffect, useState } from 'react'; | ||
import { useRef, useEffect, useState, createContext, createElement, useContext } from 'react'; | ||
@@ -80,2 +80,13 @@ /*! ***************************************************************************** | ||
}; | ||
var ClearCacheContext = createContext(null); | ||
var ClearCacheProvider = function (props) { | ||
var children = props.children; | ||
var _a = useClearCache(props), loading = _a.loading, isLatestVersion = _a.isLatestVersion, emptyCacheStorage = _a.emptyCacheStorage; | ||
return (createElement(ClearCacheContext.Provider, { value: { | ||
loading: loading, | ||
isLatestVersion: isLatestVersion, | ||
emptyCacheStorage: emptyCacheStorage | ||
} }, children)); | ||
}; | ||
var useClearCacheCtx = function () { return useContext(ClearCacheContext); }; | ||
var useClearCache = function (props) { | ||
@@ -187,3 +198,3 @@ var _a = __assign({}, defaultProps, props), duration = _a.duration, auto = _a.auto, storageKey = _a.storageKey, basePath = _a.basePath, filename = _a.filename; | ||
export default ClearCache; | ||
export { useClearCache }; | ||
export { ClearCacheProvider, useClearCacheCtx, useClearCache }; | ||
//# sourceMappingURL=index.es.js.map |
@@ -84,2 +84,13 @@ 'use strict'; | ||
}; | ||
var ClearCacheContext = React.createContext(null); | ||
var ClearCacheProvider = function (props) { | ||
var children = props.children; | ||
var _a = useClearCache(props), loading = _a.loading, isLatestVersion = _a.isLatestVersion, emptyCacheStorage = _a.emptyCacheStorage; | ||
return (React.createElement(ClearCacheContext.Provider, { value: { | ||
loading: loading, | ||
isLatestVersion: isLatestVersion, | ||
emptyCacheStorage: emptyCacheStorage | ||
} }, children)); | ||
}; | ||
var useClearCacheCtx = function () { return React.useContext(ClearCacheContext); }; | ||
var useClearCache = function (props) { | ||
@@ -190,4 +201,6 @@ var _a = __assign({}, defaultProps, props), duration = _a.duration, auto = _a.auto, storageKey = _a.storageKey, basePath = _a.basePath, filename = _a.filename; | ||
exports.ClearCacheProvider = ClearCacheProvider; | ||
exports.useClearCacheCtx = useClearCacheCtx; | ||
exports.useClearCache = useClearCache; | ||
exports.default = ClearCache; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "react-clear-cache", | ||
"version": "1.4.3", | ||
"version": "1.4.4", | ||
"description": "A component to manage application updates.", | ||
@@ -5,0 +5,0 @@ "author": "noahjohn9259", |
@@ -30,8 +30,44 @@ # react-clear-cache | ||
### 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 * as React from 'react'; | ||
import ClearCache from "react-clear-cache"; | ||
import ClearCache from 'react-clear-cache'; | ||
@@ -70,5 +106,5 @@ const App: React.FC<{}> = () => { | ||
```tsx | ||
import * as React from "react"; | ||
import * as React from 'react'; | ||
import { useClearCache } from "react-clear-cache"; | ||
import { useClearCache } from 'react-clear-cache'; | ||
@@ -75,0 +111,0 @@ const App: React.FC<{}> = () => { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
82335
443
176