Skip to content

Commit babfe02

Browse files
Theme: replacing code with custom hook
1 parent 01b256d commit babfe02

File tree

1 file changed

+5
-17
lines changed

1 file changed

+5
-17
lines changed

client/packages/lowcoder/src/comps/comps/textComp.tsx

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { CompTypeContext } from "../utils/compTypeContext";
2525
import { changeChildAction } from "lowcoder-core";
2626
import { setInitialCompStyles } from "../utils/themeUtil";
2727
import { BoolControl } from "../controls/boolControl";
28+
import { useMergeCompStyles } from "@lowcoder-ee/util/hooks";
2829

2930
const getStyle = (style: TextStyleType) => {
3031
return css`
@@ -138,27 +139,14 @@ let TextTmpComp = (function () {
138139
animationStyle: styleControl(AnimationStyle, 'animationStyle'),
139140
margin: MarginControl,
140141
padding: PaddingControl,
141-
themeApplied: BoolControl,
142142
};
143143
return new UICompBuilder(childrenMap, (props, dispatch) => {
144144
const value = props.text.value;
145-
const theme = useContext(ThemeContext);
146-
const compType = useContext(CompTypeContext);
147-
const compTheme = theme?.theme?.components?.[compType];
148-
149-
const styleProps: Record<string, any> = {};
150-
['style', 'animationStyle'].forEach((key: string) => {
151-
styleProps[key] = (props as any)[key];
152-
});
153145

154-
useEffect(() => {
155-
if (props.themeApplied) return;
156-
setInitialCompStyles({
157-
dispatch,
158-
compTheme,
159-
styleProps,
160-
});
161-
}, []);
146+
useMergeCompStyles(
147+
props as Record<string, any>,
148+
dispatch
149+
);
162150

163151
return (
164152
<TextContainer

0 commit comments

Comments
 (0)