use stale swr and disable revalidation

This commit is contained in:
spencerwooo
2021-08-29 15:50:38 +01:00
parent b54d59cbba
commit 8a5f4482cd
5 changed files with 34 additions and 21 deletions
+3 -5
View File
@@ -1,17 +1,15 @@
import { useEffect, FunctionComponent } from 'react'
import useSWR from 'swr'
import axios from 'axios'
import Prism from 'prismjs'
import { getExtension } from '../../utils/getFileIcon'
import { useStaleSWR } from '../../utils/tools'
import FourOhFour from '../FourOhFour'
import Loading from '../Loading'
import DownloadBtn from '../DownloadBtn'
const fetcher = (url: string) => axios.get(url).then(res => res.data)
const CodePreview: FunctionComponent<{ file: any }> = ({ file }) => {
const { data, error } = useSWR(file['@microsoft.graph.downloadUrl'], fetcher)
const { data, error } = useStaleSWR(file['@microsoft.graph.downloadUrl'])
useEffect(() => {
if (typeof window !== 'undefined') {
Prism.highlightAll()
+2 -5
View File
@@ -1,6 +1,4 @@
import { useEffect, FunctionComponent } from 'react'
import axios from 'axios'
import useSWR from 'swr'
import Prism from 'prismjs'
import ReactMarkdown from 'react-markdown'
import gfm from 'remark-gfm'
@@ -13,11 +11,10 @@ import 'katex/dist/katex.min.css'
import FourOhFour from '../FourOhFour'
import Loading from '../Loading'
import DownloadBtn from '../DownloadBtn'
const fetcher = (url: string) => axios.get(url).then(res => res.data)
import { useStaleSWR } from '../../utils/tools'
const MarkdownPreview: FunctionComponent<{ file: any; standalone?: boolean }> = ({ file, standalone = true }) => {
const { data, error } = useSWR(file['@microsoft.graph.downloadUrl'], fetcher)
const { data, error } = useStaleSWR(file['@microsoft.graph.downloadUrl'])
useEffect(() => {
if (typeof window !== 'undefined') {
+2 -5
View File
@@ -1,15 +1,12 @@
import axios from 'axios'
import { FunctionComponent } from 'react'
import useSWR from 'swr'
import FourOhFour from '../FourOhFour'
import Loading from '../Loading'
import DownloadBtn from '../DownloadBtn'
const fetcher = (url: string) => axios.get(url).then(res => res.data)
import { useStaleSWR } from '../../utils/tools'
const TextPreview: FunctionComponent<{ file: any }> = ({ file }) => {
const { data, error } = useSWR(file['@microsoft.graph.downloadUrl'], fetcher)
const { data, error } = useStaleSWR(file['@microsoft.graph.downloadUrl'])
if (error) {
return (
<div className="shadow bg-white dark:bg-gray-900 rounded p-3">