Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}, [callback]);
// Set up the interval.
// eslint-disable-next-line
useEffect(() => {
function tick() {
savedCallback.current();
}
if (delay !== null) {
const id = setInterval(tick, delay);
return () => clearInterval(id);
}
}, [delay]);
}
const evtTarget = new EventTarget();
const useStorage = (storage, keyPrefix) => (key, defaultValue) => {
const storeKey = `${keyPrefix}.${key}`;
const raw = storage.getItem(storeKey);
const [value, setValue] = useState(raw ? JSON.parse(raw) : defaultValue);
const updater = updatedValue => {
setValue(updatedValue);
storage.setItem(storeKey, JSON.stringify(updatedValue));
evtTarget.dispatchEvent(new CustomEvent('storage_change', { detail: { key } }));
};
if (defaultValue != null && !raw) {
updater(defaultValue);
}
useEffect(() => {
this.retries = params.retries || 5;
this.delayBeforeRetry = params.delayBeforeRetry || 5;
this.start = 0;
this.chunk = null;
this.chunkCount = 0;
this.totalChunks = Math.ceil(this.file.size / (this.chunkSize * 1000 * 1000));
this.retriesCount = 0;
this.offline = false;
this.paused = false;
this.headers['uploader-file-id'] = this._uniqid(this.file);
this.headers['uploader-chunks-total'] = this.totalChunks;
this._reader = new FileReader();
this._eventTarget = new EventTarget();
this._validateParams();
this._sendChunks();
// restart sync when back online
// trigger events when offline/back online
window.addEventListener('online', () => {
if (!this.offline) return;
this.offline = false;
this._eventTarget.dispatchEvent(new Event('online'));
this._sendChunks();
});
window.addEventListener('offline', () => {
this.offline = true;