Skip to content

Commit fce2af5

Browse files
jaygiangthgaskell
andauthored
410 - Should not show "Application is Online" notification on initial render (#470)
* Use useRef hook to track previous offline state * Fix linter warnings --------- Co-authored-by: Tony Gaskell <[email protected]>
1 parent c4e5eaa commit fce2af5

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

packages/react-radfish/Application/index.jsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
import { Toast } from "../alerts";
2-
import { createContext, useEffect, useContext } from "react";
2+
import { createContext, useEffect, useContext, useRef } from "react";
33
import { useOfflineStatus, useToasts, dispatchToast } from "../hooks";
44

55
const ApplicationContext = createContext();
66

77
function ApplicationComponent(props) {
88
const { toasts } = useToasts();
99
const { isOffline } = useOfflineStatus();
10+
const prevIsOffline = useRef(null);
1011

1112
useEffect(() => {
12-
if (!isOffline) {
13+
if (prevIsOffline.current === null) {
14+
prevIsOffline.current = isOffline;
15+
} else if (prevIsOffline.current && !isOffline) {
1316
dispatchToast({ message: "Application is online", status: "info", duration: 3000 });
1417
}
18+
prevIsOffline.current = isOffline;
1519
}, [isOffline]);
1620

1721
return (

0 commit comments

Comments
 (0)