Skip to content

Commit d589a6d

Browse files
authored
store SSG flag in state variable (#3352)
* store ssg flag in state variable * fix infinite rendering loop
1 parent d5f7d9d commit d589a6d

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

wormhole-connect/src/AppRouter.tsx

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useCallback, useContext, useEffect } from 'react';
1+
import React, { useCallback, useContext, useEffect, useRef } from 'react';
22
import { useDispatch, useSelector } from 'react-redux';
33
import { makeStyles } from 'tss-react/mui';
44

@@ -42,14 +42,14 @@ interface Props {
4242
config?: WormholeConnectConfig;
4343
}
4444

45-
let _HAS_SET_CONFIG_SSG = false;
46-
4745
// since this will be embedded, we'll have to use pseudo routes instead of relying on the url
4846
function AppRouter(props: Props) {
4947
const { classes } = useStyles();
5048
const dispatch = useDispatch();
5149
const routeContext = useContext(RouteContext);
5250

51+
const hasSetSsgConfig = useRef(false);
52+
5353
// We update the global config once when WormholeConnect is first mounted, if a custom
5454
// config was provided.
5555
//
@@ -58,7 +58,6 @@ function AppRouter(props: Props) {
5858
const loadConfig = useCallback((customConfig: WormholeConnectConfig) => {
5959
if (!isEmptyObject(customConfig)) {
6060
setConfig(customConfig);
61-
dispatch(clearTransfer());
6261
}
6362

6463
config.triggerEvent({
@@ -67,12 +66,12 @@ function AppRouter(props: Props) {
6766
});
6867
}, []);
6968

70-
if (!_HAS_SET_CONFIG_SSG) {
69+
if (!hasSetSsgConfig.current) {
7170
// This runs once in SSG step (server-side pre-rendering)
7271
if (props.config) {
7372
loadConfig(props.config);
7473
}
75-
_HAS_SET_CONFIG_SSG = true;
74+
hasSetSsgConfig.current = true;
7675
}
7776

7877
useEffect(() => {

0 commit comments

Comments
 (0)