Skip to content

Commit 036f0da

Browse files
reduced actions for global variables
1 parent 58577fe commit 036f0da

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

client/packages/lowcoder/src/comps/generators/hookToComp.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ export function hookToStateComp(useHookFn: () => JSONObject) {
3636
const hookValue = useHookFn();
3737
const stateValue = useMemo(() => comp.children.stateValue.getView(), [comp.children.stateValue]);
3838

39-
if (!isEqual(hookValue, stateValue)) {
40-
comp.children.stateValue.dispatchChangeValueAction(hookValue);
41-
}
39+
useEffect(() => {
40+
if (!isEqual(hookValue, stateValue)) {
41+
comp.children.stateValue.dispatchChangeValueAction(hookValue);
42+
}
43+
}, [hookValue, stateValue]);
4244
return null;
4345
}
4446
);

client/packages/lowcoder/src/comps/hooks/screenInfoComp.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ type ScreenInfo = {
2222
export function useScreenInfo() {
2323
const canvasContainer = document.getElementById(CanvasContainerID);
2424
const canvas = document.getElementsByClassName('lowcoder-app-canvas')?.[0];
25-
const canvasWidth = canvasContainer?.clientWidth || canvas?.clientWidth;
25+
const canvasWidth = useMemo(() => {
26+
return canvasContainer?.clientWidth || canvas?.clientWidth;
27+
}, [canvasContainer?.clientWidth, canvas?.clientWidth]);
2628

2729
const getDeviceType = (width: number) => {
2830
if (width < 768) return ScreenTypes.Mobile;
@@ -71,7 +73,9 @@ export function useScreenInfo() {
7173
}, [ updateScreenInfo ])
7274

7375
useEffect(() => {
74-
updateScreenInfo();
76+
if (canvasWidth) {
77+
updateScreenInfo();
78+
}
7579
}, [canvasWidth]);
7680

7781
return screenInfo;

client/packages/lowcoder/src/comps/hooks/themeComp.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,15 @@ let ThemeTempComp = withViewFn(
6464
return stateValue;
6565
}, [themeList, currentTheme, stateValue])
6666

67-
if (!isEqual(themeValue, stateValue)) {
68-
comp.children.stateValue.dispatchChangeValueAction({
69-
...exposingTheme(currentTheme),
70-
allThemes: themeList.map((t) => exposingTheme(t)),
71-
})
72-
}
67+
useEffect(() => {
68+
if (!isEqual(themeValue, stateValue)) {
69+
comp.children.stateValue.dispatchChangeValueAction({
70+
...exposingTheme(currentTheme),
71+
allThemes: themeList.map((t) => exposingTheme(t)),
72+
})
73+
}
74+
}, [themeValue, stateValue]);
75+
7376
return null;
7477
}
7578
);

0 commit comments

Comments
 (0)