Skip to content

Commit 0ebe353

Browse files
committed
add useToast for easier enable disable
1 parent a86040a commit 0ebe353

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

Diff for: packages/react-scripts/template/src/registerServiceWorker.js

+15-10
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import React from 'react';
1111
import ReactDOM from 'react-dom';
1212
import Toast from './Toast';
1313

14+
const useToast = true;
1415
const domId = 'create-react-app-toast';
1516
let dom = document.getElementById(domId);
1617

@@ -20,13 +21,17 @@ if (!dom) {
2021
document.body.appendChild(dom);
2122
}
2223

23-
function renderToast(message) {
24-
ReactDOM.render(
25-
<Toast timeout={3000}>
26-
{message}
27-
</Toast>,
28-
dom
29-
);
24+
function showMessage(message) {
25+
if (useToast) {
26+
ReactDOM.render(
27+
<Toast timeout={3000}>
28+
{message}
29+
</Toast>,
30+
dom
31+
);
32+
} else {
33+
console.log(message);
34+
}
3035
}
3136

3237
export default function register() {
@@ -45,12 +50,12 @@ export default function register() {
4550
// the fresh content will have been added to the cache.
4651
// It's the perfect time to display a "New content is
4752
// available; please refresh." message in your web app.
48-
renderToast('New content is available. Please refresh.');
53+
showMessage('New content is available. Please refresh.');
4954
} else {
5055
// At this point, everything has been precached.
5156
// It's the perfect time to display a
5257
// "Content is cached for offline use." message.
53-
renderToast('Content is cached for offline use.');
58+
showMessage('Content is cached for offline use.');
5459
}
5560
}
5661
};
@@ -61,7 +66,7 @@ export default function register() {
6166
});
6267
});
6368
} else {
64-
renderToast('Development mode started.');
69+
showMessage('Development mode started.');
6570
}
6671
}
6772

0 commit comments

Comments
 (0)