This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import useSWR from '@zeit/swr'; | |
import localForage from 'localforage'; | |
import { ConfigInterface } from '@zeit/swr/dist/src/types'; | |
import { useState, useEffect } from 'react'; | |
export function usePersistentSWR(key: string, fn?: Function, config?: ConfigInterface) { | |
let handleSuccess; | |
if (config !== undefined && config.onSuccess !== undefined) { | |
const { onSuccess } = config; | |
handleSuccess = (data: any, key: string, config: ConfigInterface) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Prints a warning in the console if it exists. | |
* | |
* @param {String} message The warning message. | |
* @returns {void} | |
*/ | |
function warning(message) { | |
/* eslint-disable no-console */ | |
if (typeof console !== 'undefined' && typeof console.error === 'function') { | |
console.error(message); |