Skip to content

Commit 28eeff3

Browse files
authored
fix: fix setError bug
1 parent 1bade5f commit 28eeff3

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/use/useFormItemContentController.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { useEffect, useRef } from 'react';
22
import { Apis, GlobalProps } from 'react-form-simple/types/form';
3-
import { useController } from 'react-form-simple/use/useController';
43
import useForceUpdate from 'react-form-simple/use/useForceUpdate';
54
import { FormUtil } from 'react-form-simple/utils/FormUtil';
65
import {
@@ -62,9 +61,7 @@ export function useFormItemContentController(
6261

6362
formUtil.replace({ model: modelValue.current });
6463

65-
const status = useController({ isError: false });
66-
67-
const { isError } = status;
64+
const isError = useRef(false);
6865

6966
const isInitSubscribeEvent = useRef(true);
7067

@@ -73,7 +70,10 @@ export function useFormItemContentController(
7370
methods.set(value);
7471
});
7572
subscribe.on('onErr', (value) => {
76-
status.isError = isMeaningful(value);
73+
if (isError.current !== isMeaningful(value)) {
74+
forceUpdate(false);
75+
}
76+
isError.current = isMeaningful(value);
7777
});
7878
isInitSubscribeEvent.current = false;
7979
}
@@ -82,14 +82,14 @@ export function useFormItemContentController(
8282
if (bindId !== preBindId.current) {
8383
modelValue.current = convertStringToObject(bindId, initialValue);
8484
preBindId.current = bindId;
85-
forceUpdate(false)
85+
forceUpdate(false);
8686
}
8787
}, [bindId]);
8888

8989
const methods = {
9090
set(value: any) {
9191
updateProxyValue(modelValue.current, preBindId.current as string, value);
92-
forceUpdate(false)
92+
forceUpdate(false);
9393
},
9494
};
9595

@@ -112,7 +112,7 @@ export function useFormItemContentController(
112112
value,
113113
checked: Boolean(value),
114114
},
115-
isError,
115+
isError: isError.current,
116116
...apis,
117117
}) || null;
118118

0 commit comments

Comments
 (0)