Skip to content

Commit 54acc79

Browse files
committed
fix: cross browser support
1 parent 28a15c3 commit 54acc79

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

index.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ let firstRender = false;
55
let oldArgs: any = {};
66

77
const useContextDevTools = (dispatch: Function) => {
8-
if (!isInitialized) {
8+
if (!isInitialized && (window as any).__REDUX_DEVTOOLS_EXTENSION__) {
99
devTools.current = (window as any).__REDUX_DEVTOOLS_EXTENSION__.connect({
1010
features: {
1111
pause: true, // start/pause recording of dispatched actions
@@ -54,18 +54,22 @@ const useContextDevTools = (dispatch: Function) => {
5454
};
5555

5656
const sendUpdatedState = (updatedState: any) => {
57-
if (!firstRender) {
58-
devTools.current.init(updatedState);
59-
firstRender = true;
60-
} else {
61-
if (oldArgs.type !== 'IMPORT_STATE') {
62-
devTools.current.send(oldArgs, updatedState);
57+
if ((window as any).__REDUX_DEVTOOLS_EXTENSION__){
58+
if (!firstRender) {
59+
devTools.current.init(updatedState);
60+
firstRender = true;
61+
} else {
62+
if (oldArgs.type !== 'IMPORT_STATE') {
63+
devTools.current.send(oldArgs, updatedState);
64+
}
6365
}
6466
}
6567
};
6668

6769
const disconnectDevTools = () => {
68-
return typeof devTools?.current?.disconnect === 'function' && devTools?.current?.disconnect();
70+
if ((window as any).__REDUX_DEVTOOLS_EXTENSION__){
71+
return typeof devTools?.current?.disconnect === 'function' && devTools?.current?.disconnect();
72+
}
6973
}
7074

7175
return {

0 commit comments

Comments
 (0)