aidenybai / aidenybai/react-scan

Conditionally enable react-scan

未關閉
#47 11 則留言 4 個 reaction 已指派 1 人 已被 @pivanov 認領 在 GitHub 檢視
主要語言
TypeScript
星號
21.8k
分支
390
平均合併
23 分鐘
30 天內合併 PR
1

描述

## Question

Hi there 👋, the README suggests the following to use `react-scan` programmatically:
```
import { scan } from 'react-scan'; // import this BEFORE react
import React from 'react';

if (typeof window !== 'undefined') {
scan({
enabled: true,
log: true, // logs render info to console (default: false)
});
}
```

However, if we want to only load `react-scan` in local builds, and allow for easy enabling and disabling, is that possible? If so, how?

## Ideal API
My ideal API would be something like this:
```
import React from 'react';

function enableScanning() {
import('react-scan').then(({ scan }) => {
scan({
enabled: true,
log: true,
});
});
}

const AdminPanel = () => {
return (
...
Enable React Scan
Disable React Scan
...
)
}
```

But given the comment about `react-scan` needing to be imported before `react`, it seems like that won't be possible. Is that accurate?

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。