Skip to content

Commit 780ca30

Browse files
fixed input state change not updating temporary state value
1 parent b60860a commit 780ca30

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

client/packages/lowcoder/src/comps/comps/textInputComp/textInputConstants.tsx

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { stringExposingStateControl } from "comps/controls/codeStateControl";
1111
import { LabelControl } from "comps/controls/labelControl";
1212
import { InputLikeStyleType, LabelStyleType, heightCalculator, widthCalculator } from "comps/controls/styleControlConstants";
1313
import { Section, sectionNames, ValueFromOption } from "lowcoder-design";
14-
import _, { debounce } from "lodash";
14+
import { fromPairs } from "lodash";
1515
import { css } from "styled-components";
1616
import { EMAIL_PATTERN, URL_PATTERN } from "util/stringUtils";
1717
import { MultiBaseComp, RecordConstructorToComp, RecordConstructorToView } from "lowcoder-core";
@@ -84,7 +84,7 @@ type ValidationParams = {
8484
customRule: string;
8585
};
8686

87-
const valueInfoMap = _.fromPairs(
87+
const valueInfoMap = fromPairs(
8888
TextInputValidationOptions.map((option) => [option.value, option])
8989
);
9090

@@ -216,26 +216,19 @@ export const useTextInputProps = (props: RecordConstructorToView<typeof textInpu
216216
);
217217
}, [props.customRule])
218218

219-
const debouncedOnChangeRef = useRef(
220-
debounce((value: string) => {
219+
const onChangeRef = useRef(
220+
(value: string) => {
221221
props.value.onChange(value);
222-
}, 1000)
222+
}
223223
);
224224

225-
// Cleanup debounced function on unmount
226-
useEffect(() => {
227-
return () => {
228-
debouncedOnChangeRef.current.cancel();
229-
};
230-
}, []);
231-
232225
const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
233226
const value = e.target.value;
234227
setLocalInputValue(value);
235228

236229
changeRef.current = true;
237230
touchRef.current = true;
238-
debouncedOnChangeRef.current?.(value);
231+
onChangeRef.current?.(value);
239232
};
240233

241234
// Cleanup refs on unmount
@@ -244,6 +237,7 @@ export const useTextInputProps = (props: RecordConstructorToView<typeof textInpu
244237
changeRef.current = false;
245238
touchRef.current = false;
246239
propsRef.current = null as any;
240+
onChangeRef.current = null as any;
247241
};
248242
}, []);
249243

0 commit comments

Comments
 (0)