aidenybai / aidenybai/react-scan

Conditionally enable react-scan

Đang mở
#47 11 bình luận 4 reaction 1 người được giao Được @pivanov nhận Xem trên GitHub
Ngôn ngữ chính
TypeScript
Star
21.8k
Fork
390
Merge trung bình
23 phút
Pull request đã merge (30 ngày)
1

Mô tả

## 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?

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.