-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathdevtools.ts
More file actions
31 lines (26 loc) · 872 Bytes
/
devtools.ts
File metadata and controls
31 lines (26 loc) · 872 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import React from 'react'
import { isWindowDefined } from './helper'
// @ts-expect-error
const enableDevtools = isWindowDefined && window.__SWR_DEVTOOLS_USE__
export const getDevToolsUse = () => {
if (!isWindowDefined) return []
// @ts-expect-error
return window.__SWR_DEVTOOLS_USE__ ?? []
}
export const setupDevTools = () => {
if (enableDevtools) {
// @ts-expect-error
window.__SWR_DEVTOOLS_REACT__ = React
}
}
// Due to Chrome extension limitations, the SWR DevTools extension may inject
// `__SWR_DEVTOOLS_USE__` too late, where `enableDevtools` will always be false
// In this case, we provide a global function `__SWR_DEVTOOLS_SETUP__` for the
// extension to invoke when it is ready
if (isWindowDefined) {
// @ts-expect-error
window.__SWR_DEVTOOLS_SETUP__ = () => {
// @ts-expect-error
window.__SWR_DEVTOOLS_REACT__ = React
}
}